@ledgerhq/revault-sdk 0.20.0 → 0.21.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 +27 -9
- package/lib/bake.cjs.map +1 -1
- package/lib/bake.d.cts +102 -102
- package/lib/bake.d.ts +102 -102
- package/lib/bake.js +26 -8
- package/lib/bake.js.map +1 -1
- package/lib/chunk-CZLZUISN.js +262 -0
- package/lib/chunk-CZLZUISN.js.map +1 -0
- package/lib/chunk-JGXOGWYB.cjs +262 -0
- package/lib/chunk-JGXOGWYB.cjs.map +1 -0
- package/lib/{chunk-UCQR7XCK.cjs → chunk-PHC5IG6P.cjs} +1 -1
- package/lib/chunk-PHC5IG6P.cjs.map +1 -0
- package/lib/{chunk-7F2SX4FL.js → chunk-VMABO6WZ.js} +1 -1
- package/lib/chunk-VMABO6WZ.js.map +1 -0
- package/lib/crypto.cjs +3 -257
- package/lib/crypto.cjs.map +1 -1
- package/lib/crypto.js +3 -257
- package/lib/crypto.js.map +1 -1
- package/lib/device.cjs +2 -2
- package/lib/device.d.cts +1 -1
- package/lib/device.d.ts +1 -1
- package/lib/device.js +1 -1
- package/lib/engine.cjs +21 -21
- package/lib/engine.cjs.map +1 -1
- package/lib/engine.d.cts +4 -4
- package/lib/engine.d.ts +4 -4
- package/lib/engine.js +1 -1
- package/lib/engine.js.map +1 -1
- package/lib/index.d.cts +3 -3
- package/lib/index.d.ts +3 -3
- package/lib/{types-DNEewSJL.d.cts → logger-C-TPbnjv.d.cts} +1 -5
- package/lib/{types-DNEewSJL.d.ts → logger-C-TPbnjv.d.ts} +1 -5
- package/lib/onboarding.cjs.map +1 -1
- package/lib/onboarding.d.cts +3 -3
- package/lib/onboarding.d.ts +3 -3
- package/lib/onboarding.js.map +1 -1
- package/lib/{types-mZnXORz9.d.ts → types-Cp-L-rsW.d.ts} +1 -1
- package/lib/{index-znHBELBb.d.ts → types-Ct-F-l82.d.cts} +2 -3
- package/lib/{index-YRqsGEDY.d.cts → types-Ct-F-l82.d.ts} +2 -3
- package/lib/{types-CAKnCFJk.d.cts → types-DEyShR5S.d.cts} +1 -1
- package/lib/types.cjs +1 -0
- package/lib/types.cjs.map +1 -0
- package/lib/types.d.cts +4 -0
- package/lib/types.d.ts +4 -0
- package/lib/types.js +1 -0
- package/lib/types.js.map +1 -0
- package/package.json +17 -12
- package/lib/chunk-7F2SX4FL.js.map +0 -1
- package/lib/chunk-UCQR7XCK.cjs.map +0 -1
package/lib/crypto.js
CHANGED
|
@@ -1,260 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// src/crypto/key-encoder.ts
|
|
6
|
-
import asn1 from "asn1.js";
|
|
7
|
-
import BN from "bn.js";
|
|
8
|
-
import elliptic from "elliptic";
|
|
9
|
-
var ECPrivateKeyASN = asn1.define("ECPrivateKey", function() {
|
|
10
|
-
const self = this;
|
|
11
|
-
self.seq().obj(
|
|
12
|
-
self.key("version").int(),
|
|
13
|
-
self.key("privateKey").octstr(),
|
|
14
|
-
self.key("parameters").explicit(0).objid().optional(),
|
|
15
|
-
self.key("publicKey").explicit(1).bitstr().optional()
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
var ECPrivateKey8ASN = asn1.define(
|
|
19
|
-
"ECPrivateKey",
|
|
20
|
-
/* v8 ignore start */
|
|
21
|
-
function() {
|
|
22
|
-
const self = this;
|
|
23
|
-
self.seq().obj(
|
|
24
|
-
self.key("version").int(),
|
|
25
|
-
self.key("privateKeyAlgorithm").seq().obj(self.key("ecPublicKey").objid(), self.key("curve").objid()),
|
|
26
|
-
self.key("privateKey").octstr().contains(ECPrivateKeyASN),
|
|
27
|
-
self.key("attributes").explicit(0).bitstr().optional()
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
/* v8 ignore stop */
|
|
31
|
-
);
|
|
32
|
-
var SubjectPublicKeyInfoASN = asn1.define("SubjectPublicKeyInfo", function() {
|
|
33
|
-
const self = this;
|
|
34
|
-
self.seq().obj(
|
|
35
|
-
self.key("algorithm").seq().obj(self.key("id").objid(), self.key("curve").objid()),
|
|
36
|
-
self.key("pub").bitstr()
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
var curves = {
|
|
40
|
-
secp256k1: {
|
|
41
|
-
curveParameters: [1, 3, 132, 0, 10],
|
|
42
|
-
privatePEMOptions: { label: "EC PRIVATE KEY" },
|
|
43
|
-
publicPEMOptions: { label: "PUBLIC KEY" },
|
|
44
|
-
curve: new elliptic.ec("secp256k1")
|
|
45
|
-
},
|
|
46
|
-
p256: {
|
|
47
|
-
curveParameters: [1, 2, 840, 10045, 3, 1, 7],
|
|
48
|
-
// OID for p256 curve
|
|
49
|
-
privatePEMOptions: { label: "EC PRIVATE KEY" },
|
|
50
|
-
publicPEMOptions: { label: "PUBLIC KEY" },
|
|
51
|
-
curve: new elliptic.ec("p256")
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var KeyEncoder = class {
|
|
55
|
-
algorithmID;
|
|
56
|
-
options;
|
|
57
|
-
constructor(options) {
|
|
58
|
-
if (typeof options === "string") {
|
|
59
|
-
if (options !== "secp256k1" && options !== "p256") {
|
|
60
|
-
throw new Error("Unknown curve " + options);
|
|
61
|
-
}
|
|
62
|
-
options = curves[options];
|
|
63
|
-
}
|
|
64
|
-
this.options = options;
|
|
65
|
-
this.algorithmID = [1, 2, 840, 10045, 2, 1];
|
|
66
|
-
}
|
|
67
|
-
/* v8 ignore start */
|
|
68
|
-
PKCS1toPKCS8(privateKey) {
|
|
69
|
-
return {
|
|
70
|
-
version: new BN(0),
|
|
71
|
-
privateKey,
|
|
72
|
-
privateKeyAlgorithm: {
|
|
73
|
-
ecPublicKey: this.algorithmID,
|
|
74
|
-
curve: privateKey.parameters
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/* v8 ignore stop */
|
|
79
|
-
privateKeyObject(rawPrivateKey, rawPublicKey) {
|
|
80
|
-
const privateKeyObject = {
|
|
81
|
-
version: new BN(1),
|
|
82
|
-
privateKey: Buffer.from(rawPrivateKey, "hex"),
|
|
83
|
-
parameters: this.options.curveParameters
|
|
84
|
-
};
|
|
85
|
-
if (rawPublicKey) {
|
|
86
|
-
privateKeyObject.publicKey = {
|
|
87
|
-
unused: 0,
|
|
88
|
-
data: Buffer.from(rawPublicKey, "hex")
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return privateKeyObject;
|
|
92
|
-
}
|
|
93
|
-
publicKeyObject(rawPublicKey) {
|
|
94
|
-
return {
|
|
95
|
-
algorithm: {
|
|
96
|
-
id: this.algorithmID,
|
|
97
|
-
curve: this.options.curveParameters
|
|
98
|
-
},
|
|
99
|
-
pub: {
|
|
100
|
-
unused: 0,
|
|
101
|
-
data: Buffer.from(rawPublicKey, "hex")
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
encodePrivate(privateKey, originalFormat, destinationFormat, destinationFormatType = "pkcs1") {
|
|
106
|
-
let privateKeyObject;
|
|
107
|
-
switch (originalFormat) {
|
|
108
|
-
case "raw": {
|
|
109
|
-
if (typeof privateKey !== "string") {
|
|
110
|
-
throw new Error("private key must be a string");
|
|
111
|
-
}
|
|
112
|
-
const keyPair = this.options.curve.keyFromPrivate(privateKey, "hex");
|
|
113
|
-
const rawPublicKey = keyPair.getPublic("hex");
|
|
114
|
-
privateKeyObject = this.privateKeyObject(privateKey, rawPublicKey);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case "der":
|
|
118
|
-
if (typeof privateKey === "string") {
|
|
119
|
-
privateKey = Buffer.from(privateKey, "hex");
|
|
120
|
-
}
|
|
121
|
-
privateKeyObject = ECPrivateKeyASN.decode(privateKey, "der");
|
|
122
|
-
break;
|
|
123
|
-
case "pem":
|
|
124
|
-
if (typeof privateKey !== "string") {
|
|
125
|
-
throw new Error("private key must be a string");
|
|
126
|
-
}
|
|
127
|
-
privateKeyObject = ECPrivateKeyASN.decode(
|
|
128
|
-
privateKey,
|
|
129
|
-
"pem",
|
|
130
|
-
this.options.privatePEMOptions
|
|
131
|
-
);
|
|
132
|
-
break;
|
|
133
|
-
/* v8 ignore start */
|
|
134
|
-
default:
|
|
135
|
-
throw new Error("invalid private key format");
|
|
136
|
-
}
|
|
137
|
-
switch (destinationFormat) {
|
|
138
|
-
case "raw":
|
|
139
|
-
if (destinationFormatType === "pkcs1") {
|
|
140
|
-
return privateKeyObject.privateKey.toString("hex");
|
|
141
|
-
} else if (destinationFormatType === "pkcs8") {
|
|
142
|
-
return this.PKCS1toPKCS8(privateKeyObject).privateKey.privateKey.toString("hex");
|
|
143
|
-
}
|
|
144
|
-
break;
|
|
145
|
-
case "der":
|
|
146
|
-
if (destinationFormatType === "pkcs1") {
|
|
147
|
-
return ECPrivateKeyASN.encode(privateKeyObject, "der").toString("hex");
|
|
148
|
-
} else if (destinationFormatType === "pkcs8") {
|
|
149
|
-
return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), "der").toString(
|
|
150
|
-
"hex"
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
case "pem":
|
|
155
|
-
if (destinationFormatType === "pkcs1") {
|
|
156
|
-
return ECPrivateKeyASN.encode(privateKeyObject, "pem", this.options.privatePEMOptions);
|
|
157
|
-
} else if (destinationFormatType === "pkcs8") {
|
|
158
|
-
return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), "pem", {
|
|
159
|
-
...this.options.privatePEMOptions,
|
|
160
|
-
label: "PRIVATE KEY"
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
break;
|
|
164
|
-
/* v8 ignore start */
|
|
165
|
-
default:
|
|
166
|
-
throw new Error("invalid destination format for private key");
|
|
167
|
-
}
|
|
168
|
-
throw new Error("unsupported destination format or type");
|
|
169
|
-
}
|
|
170
|
-
encodePublic(publicKey, originalFormat, destinationFormat) {
|
|
171
|
-
let publicKeyObject;
|
|
172
|
-
switch (originalFormat) {
|
|
173
|
-
case "raw":
|
|
174
|
-
if (typeof publicKey !== "string") {
|
|
175
|
-
throw new Error("public key must be a string");
|
|
176
|
-
}
|
|
177
|
-
publicKeyObject = this.publicKeyObject(publicKey);
|
|
178
|
-
break;
|
|
179
|
-
case "der":
|
|
180
|
-
if (typeof publicKey === "string") {
|
|
181
|
-
publicKey = Buffer.from(publicKey, "hex");
|
|
182
|
-
}
|
|
183
|
-
publicKeyObject = SubjectPublicKeyInfoASN.decode(publicKey, "der");
|
|
184
|
-
break;
|
|
185
|
-
case "pem":
|
|
186
|
-
if (typeof publicKey !== "string") {
|
|
187
|
-
throw new Error("public key must be a string");
|
|
188
|
-
}
|
|
189
|
-
publicKeyObject = SubjectPublicKeyInfoASN.decode(
|
|
190
|
-
publicKey,
|
|
191
|
-
"pem",
|
|
192
|
-
this.options.publicPEMOptions
|
|
193
|
-
);
|
|
194
|
-
break;
|
|
195
|
-
/* v8 ignore start */
|
|
196
|
-
default:
|
|
197
|
-
throw new Error("invalid public key format");
|
|
198
|
-
}
|
|
199
|
-
switch (destinationFormat) {
|
|
200
|
-
case "raw":
|
|
201
|
-
return publicKeyObject.pub.data.toString("hex");
|
|
202
|
-
case "der":
|
|
203
|
-
return SubjectPublicKeyInfoASN.encode(publicKeyObject, "der").toString("hex");
|
|
204
|
-
case "pem":
|
|
205
|
-
return SubjectPublicKeyInfoASN.encode(
|
|
206
|
-
publicKeyObject,
|
|
207
|
-
"pem",
|
|
208
|
-
this.options.publicPEMOptions
|
|
209
|
-
);
|
|
210
|
-
/* v8 ignore start */
|
|
211
|
-
default:
|
|
212
|
-
throw new Error("invalid destination format for public key");
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// src/crypto/utils.ts
|
|
218
|
-
function extractPublicKey(pemKey) {
|
|
219
|
-
const pem = pemKey.split("\n");
|
|
220
|
-
pem.shift();
|
|
221
|
-
pem.pop();
|
|
222
|
-
const keyBuffer = Buffer.from(pem.join(""), "base64");
|
|
223
|
-
const actualKeyBuffer = keyBuffer.slice(26);
|
|
224
|
-
return actualKeyBuffer.toString("hex");
|
|
225
|
-
}
|
|
226
|
-
function hexToPem(hexString, { isPrivate = true } = {}) {
|
|
227
|
-
const keyEncoder = new KeyEncoder("p256");
|
|
228
|
-
if (isPrivate) {
|
|
229
|
-
return keyEncoder.encodePrivate(hexString, "raw", "pem");
|
|
230
|
-
}
|
|
231
|
-
return keyEncoder.encodePublic(hexString, "raw", "pem");
|
|
232
|
-
}
|
|
233
|
-
function genKeys(entropy) {
|
|
234
|
-
if (entropy) {
|
|
235
|
-
const ec = new elliptic2.ec("p256");
|
|
236
|
-
const hashedEntropy = crypto.createHash("sha256").update(entropy).digest("hex");
|
|
237
|
-
const keyPair = ec.genKeyPair({
|
|
238
|
-
entropy: Buffer.from(hashedEntropy, "hex")
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
privateKey: String(hexToPem(keyPair.getPrivate("hex"))),
|
|
242
|
-
publicKey: String(hexToPem(keyPair.getPublic("hex"), { isPrivate: false })),
|
|
243
|
-
hexPubKey: extractPublicKey(String(hexToPem(keyPair.getPublic("hex"), { isPrivate: false })))
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
const { publicKey, privateKey } = crypto.generateKeyPairSync("ec", {
|
|
247
|
-
namedCurve: "P-256",
|
|
248
|
-
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
249
|
-
privateKeyEncoding: { type: "sec1", format: "pem" }
|
|
250
|
-
});
|
|
251
|
-
const hexPubKey = extractPublicKey(publicKey);
|
|
252
|
-
return {
|
|
253
|
-
privateKey,
|
|
254
|
-
publicKey,
|
|
255
|
-
hexPubKey
|
|
256
|
-
};
|
|
257
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
genKeys
|
|
3
|
+
} from "./chunk-CZLZUISN.js";
|
|
258
4
|
export {
|
|
259
5
|
genKeys
|
|
260
6
|
};
|
package/lib/crypto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/crypto/utils.ts","../src/crypto/key-encoder.ts"],"sourcesContent":["import crypto from \"crypto\";\nimport elliptic from \"elliptic\";\n\nimport { KeyEncoder } from \"./key-encoder\";\nimport type { GeneratedKeys } from \"./types\";\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\");\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","// ========================================================================== //\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion\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 start */\n function () {\n // @ts-expect-error pure black box\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion\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 /* v8 ignore stop */\n);\n\nconst SubjectPublicKeyInfoASN = asn1.define(\"SubjectPublicKeyInfo\", function () {\n // @ts-expect-error pure black box\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-type-assertion\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 if (typeof options === \"string\") {\n /* v8 ignore start */\n if (options !== \"secp256k1\" && options !== \"p256\") {\n throw new Error(\"Unknown curve \" + options);\n }\n /* v8 ignore stop */\n options = curves[options]!;\n }\n this.options = options;\n this.algorithmID = [1, 2, 840, 10045, 2, 1];\n }\n\n /* v8 ignore start */\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 /* v8 ignore stop */\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 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 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 start */\n default:\n throw new Error(\"invalid private key format\");\n /* v8 ignore stop */\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 start */\n default:\n throw new Error(\"invalid destination format for private key\");\n /* v8 ignore stop */\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 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 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 start */\n default:\n throw new Error(\"invalid public key format\");\n /* v8 ignore stop */\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 start */\n default:\n throw new Error(\"invalid destination format for public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AAG,EAAE,WAAW,MAAM,CAAC,CAAC,CAAC;AAAA,IAC9F;AAAA,EACF;AACA,QAAM,EAAE,WAAW,WAAW,IAAI,OAAO,oBAAoB,MAAM;AAAA,IACjE,YAAY;AAAA,IACZ,mBAAmB,EAAE,MAAM,QAAQ,QAAQ,MAAM;AAAA,IACjD,oBAAoB,EAAE,MAAM,QAAQ,QAAQ,MAAM;AAAA,EACpD,CAAC;AACD,QAAM,YAAY,iBAAiB,SAAS;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["elliptic","elliptic"]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/lib/device.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkPHC5IG6Pcjs = require('./chunk-PHC5IG6P.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.createApiDevice =
|
|
12
|
+
exports.createApiDevice = _chunkPHC5IG6Pcjs.createApiDevice; exports.isDeviceCancelError = _chunkPHC5IG6Pcjs.isDeviceCancelError; exports.isTransportStatusError = _chunkPHC5IG6Pcjs.isTransportStatusError; exports.registerTransportModule = _chunkPHC5IG6Pcjs.registerTransportModule;
|
|
13
13
|
//# sourceMappingURL=device.cjs.map
|
package/lib/device.d.cts
CHANGED
package/lib/device.d.ts
CHANGED
package/lib/device.js
CHANGED
package/lib/engine.cjs
CHANGED
|
@@ -14,7 +14,7 @@ var _chunkWVCYFF2Zcjs = require('./chunk-WVCYFF2Z.cjs');
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunkPHC5IG6Pcjs = require('./chunk-PHC5IG6P.cjs');
|
|
18
18
|
|
|
19
19
|
// src/engine/index.ts
|
|
20
20
|
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
@@ -38,7 +38,7 @@ var splitChunks = (chunk, buffer) => {
|
|
|
38
38
|
}
|
|
39
39
|
return chunks;
|
|
40
40
|
};
|
|
41
|
-
var removeStatus = (result) => result.slice(0, result.length -
|
|
41
|
+
var removeStatus = (result) => result.slice(0, result.length - _chunkPHC5IG6Pcjs.STATUS_LENGTH);
|
|
42
42
|
var sendByChunk = async (transport, command, data, chunkSize = MAX_CHUNK_LENGTH) => {
|
|
43
43
|
const chunks = splitChunks(chunkSize, data);
|
|
44
44
|
let response = Buffer.from([]);
|
|
@@ -48,7 +48,7 @@ var sendByChunk = async (transport, command, data, chunkSize = MAX_CHUNK_LENGTH)
|
|
|
48
48
|
apdu[2] = i && 128;
|
|
49
49
|
response = await transport.send(apdu[0], apdu[1], apdu[2], apdu[3], chunk, [
|
|
50
50
|
36864,
|
|
51
|
-
...
|
|
51
|
+
..._chunkPHC5IG6Pcjs.PAGINATED_STATUS
|
|
52
52
|
]);
|
|
53
53
|
}
|
|
54
54
|
return response;
|
|
@@ -91,7 +91,7 @@ var buildAttestation = (params) => {
|
|
|
91
91
|
};
|
|
92
92
|
var genericRetryOnError = (err) => {
|
|
93
93
|
if (err instanceof _errors.LockedDeviceError) return true;
|
|
94
|
-
if (
|
|
94
|
+
if (_chunkPHC5IG6Pcjs.isTransportStatusError.call(void 0, err) && err.statusCode === 27913) return true;
|
|
95
95
|
if (err instanceof _errors.DisconnectedDevice) return true;
|
|
96
96
|
return false;
|
|
97
97
|
};
|
|
@@ -99,7 +99,7 @@ function createRealDevice(options, logger) {
|
|
|
99
99
|
const { transportId } = options;
|
|
100
100
|
async function run(job, retryOnError = genericRetryOnError) {
|
|
101
101
|
return _rxjs.lastValueFrom.call(void 0,
|
|
102
|
-
|
|
102
|
+
_chunkPHC5IG6Pcjs.withDevicePolling.call(void 0, transportId)((transport) => _rxjs.from.call(void 0, job(transport)), retryOnError)
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
const noRetry = () => false;
|
|
@@ -112,10 +112,10 @@ function createRealDevice(options, logger) {
|
|
|
112
112
|
_nullishCoalesce(opts.retryOnError, () => ( alwaysRetry))
|
|
113
113
|
);
|
|
114
114
|
try {
|
|
115
|
-
await getPublicKey(
|
|
115
|
+
await getPublicKey(_chunkPHC5IG6Pcjs.PATHS.U2F, { secp256k1: true, retryOnError: noRetry });
|
|
116
116
|
return { isAppOpened: true };
|
|
117
117
|
} catch (err) {
|
|
118
|
-
if (
|
|
118
|
+
if (_chunkPHC5IG6Pcjs.isTransportStatusError.call(void 0, err) && genericRetryOnError(err)) {
|
|
119
119
|
return { isAppOpened: false };
|
|
120
120
|
}
|
|
121
121
|
throw err;
|
|
@@ -146,18 +146,18 @@ function createRealDevice(options, logger) {
|
|
|
146
146
|
);
|
|
147
147
|
const pubKeyLength = response.readInt8(0);
|
|
148
148
|
const pubKey = response.slice(1, pubKeyLength + 1).toString("hex").toUpperCase();
|
|
149
|
-
const signature = response.slice(pubKeyLength + 1, response.length -
|
|
149
|
+
const signature = response.slice(pubKeyLength + 1, response.length - _chunkPHC5IG6Pcjs.STATUS_LENGTH).toString("base64");
|
|
150
150
|
return { pubKey, signature };
|
|
151
151
|
};
|
|
152
152
|
const device = {
|
|
153
153
|
authenticate: async ({ challenge: { challenge, name, role, keyHandle }, workspaceName }) => {
|
|
154
154
|
logger.info(`[device] Authenticate`);
|
|
155
155
|
_invariant2.default.call(void 0, role !== "READ_ONLY_API_KEY", "Invalid role for authenticate: READ_ONLY_API_KEY");
|
|
156
|
-
const applicationBuffer = Buffer.from(
|
|
156
|
+
const applicationBuffer = Buffer.from(_chunkPHC5IG6Pcjs.APPID_VAULT_ADMINISTRATOR, "hex");
|
|
157
157
|
const nameBuffer = Buffer.from(name);
|
|
158
158
|
const workspaceBuffer = Buffer.from(workspaceName);
|
|
159
159
|
const keyHandleData = Buffer.concat([
|
|
160
|
-
Buffer.from(
|
|
160
|
+
Buffer.from(_chunkPHC5IG6Pcjs.STR_ROLES[role], "hex"),
|
|
161
161
|
Buffer.from([nameBuffer.length]),
|
|
162
162
|
nameBuffer,
|
|
163
163
|
Buffer.from([workspaceBuffer.length]),
|
|
@@ -211,10 +211,10 @@ function createRealDevice(options, logger) {
|
|
|
211
211
|
confidentialityKeySignature: sig.toString("hex")
|
|
212
212
|
};
|
|
213
213
|
},
|
|
214
|
-
getConfidentialityPubKey: () => getPublicKey(
|
|
214
|
+
getConfidentialityPubKey: () => getPublicKey(_chunkPHC5IG6Pcjs.PATHS.CONFIDENTIALITY, { secp256k1: true }),
|
|
215
215
|
getDeviceUserId: FIXME_NOT_IMPLEMENTED("getDeviceUserId"),
|
|
216
|
-
getU2FPubKey: () => getPublicKey(
|
|
217
|
-
getValidationPubKey: () => getPublicKey(
|
|
216
|
+
getU2FPubKey: () => getPublicKey(_chunkPHC5IG6Pcjs.PATHS.U2F, { secp256k1: false }),
|
|
217
|
+
getValidationPubKey: () => getPublicKey(_chunkPHC5IG6Pcjs.PATHS.VALIDATION, { secp256k1: true }),
|
|
218
218
|
hasPairing: async () => {
|
|
219
219
|
logger.info(`[device] hasPairing`);
|
|
220
220
|
const apdu = [224, 81, 0, 0, 181];
|
|
@@ -226,7 +226,7 @@ function createRealDevice(options, logger) {
|
|
|
226
226
|
const res = await run((transport) => transport.send(224, 70, 0, 0));
|
|
227
227
|
const pubKeyLength = res.readInt8(0);
|
|
228
228
|
const pubKey = res.slice(1, pubKeyLength + 1).toString("hex").toUpperCase();
|
|
229
|
-
const signature = res.slice(pubKeyLength + 1, res.length -
|
|
229
|
+
const signature = res.slice(pubKeyLength + 1, res.length - _chunkPHC5IG6Pcjs.STATUS_LENGTH).toString("base64");
|
|
230
230
|
return { pubKey, signature };
|
|
231
231
|
},
|
|
232
232
|
openSession: FIXME_NOT_IMPLEMENTED("openSession"),
|
|
@@ -234,11 +234,11 @@ function createRealDevice(options, logger) {
|
|
|
234
234
|
const { challenge: strChallenge, u2fRegisterData: _, name, role } = params;
|
|
235
235
|
const challenge = Buffer.from(strChallenge, "hex");
|
|
236
236
|
_invariant2.default.call(void 0, challenge.length === 32, "challenge hex is expected to have 32 bytes");
|
|
237
|
-
const applicationBuf = Buffer.from(
|
|
237
|
+
const applicationBuf = Buffer.from(_chunkPHC5IG6Pcjs.APPID_VAULT_ADMINISTRATOR, "hex");
|
|
238
238
|
_invariant2.default.call(void 0, applicationBuf.length === 32, "application hex is expected to have 32 bytes");
|
|
239
239
|
const userNameBuff = Buffer.from(name);
|
|
240
240
|
const keyHandleData = Buffer.concat([
|
|
241
|
-
Buffer.from(
|
|
241
|
+
Buffer.from(_chunkPHC5IG6Pcjs.STR_ROLES[role], "hex"),
|
|
242
242
|
Buffer.from([userNameBuff.length]),
|
|
243
243
|
userNameBuff
|
|
244
244
|
]);
|
|
@@ -280,12 +280,12 @@ function createRealDevice(options, logger) {
|
|
|
280
280
|
logger.info(`[device] startKPatternAsResponder`);
|
|
281
281
|
const data = buildAttestation(params);
|
|
282
282
|
await run(
|
|
283
|
-
(transport) => sendByChunk(transport, [224, 73, 0,
|
|
283
|
+
(transport) => sendByChunk(transport, [224, 73, 0, _chunkPHC5IG6Pcjs.SCRIPT_IDS.ACCOUNT_MANAGER_SESSION], data)
|
|
284
284
|
);
|
|
285
285
|
},
|
|
286
286
|
validateVaultOperation: async (params) => {
|
|
287
287
|
logger.info(`[device] validateVaultOperation`);
|
|
288
|
-
const path = getPathFromPathString(
|
|
288
|
+
const path = getPathFromPathString(_chunkPHC5IG6Pcjs.PATHS.VALIDATION);
|
|
289
289
|
const paths = Buffer.concat([
|
|
290
290
|
Buffer.from([path.length]),
|
|
291
291
|
...path.map((derivation) => {
|
|
@@ -306,9 +306,9 @@ function createRealDevice(options, logger) {
|
|
|
306
306
|
);
|
|
307
307
|
const responseType = response.readInt8(0);
|
|
308
308
|
let responseStatus = response.readUInt16BE(response.length - 2);
|
|
309
|
-
if (responseType ===
|
|
309
|
+
if (responseType === _chunkPHC5IG6Pcjs.STREAMING_NEXT_ACTION) {
|
|
310
310
|
nextActionId = response.readUIntBE(1, 2);
|
|
311
|
-
} else if (responseType ===
|
|
311
|
+
} else if (responseType === _chunkPHC5IG6Pcjs.STREAMING_RESPONSE) {
|
|
312
312
|
finalResponse = response.slice(3, response.length - 2);
|
|
313
313
|
while (responseStatus !== 36864) {
|
|
314
314
|
const resp = await run((transport) => transport.send(0, 192, 0, 0));
|
|
@@ -426,7 +426,7 @@ function createEngine(options, logger) {
|
|
|
426
426
|
baseUrl: options.baseUrl
|
|
427
427
|
};
|
|
428
428
|
const client = createClient(clientOptions);
|
|
429
|
-
const apiDevice =
|
|
429
|
+
const apiDevice = _chunkPHC5IG6Pcjs.createApiDevice.call(void 0, options, logger);
|
|
430
430
|
const base = {
|
|
431
431
|
client,
|
|
432
432
|
createClient: (overrides) => createClient({ ...clientOptions, ...overrides })
|