@ledgerhq/revault-sdk 0.21.0 → 0.21.2
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 +101 -101
- package/lib/bake.d.ts +101 -101
- 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/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/engine.d.cts +3 -3
- package/lib/engine.d.ts +3 -3
- package/lib/index.d.cts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/onboarding.d.cts +2 -2
- package/lib/onboarding.d.ts +2 -2
- package/lib/{types-DRJ-VSEJ.d.ts → types-Cp-L-rsW.d.ts} +1 -1
- package/lib/{index-Ckpsy2Dz.d.ts → types-Ct-F-l82.d.cts} +2 -3
- package/lib/{index-CSP28O_x.d.cts → types-Ct-F-l82.d.ts} +2 -3
- package/lib/{types-BoemqbL9.d.cts → types-DEyShR5S.d.cts} +1 -1
- package/lib/types.d.cts +3 -0
- package/lib/types.d.ts +3 -0
- package/package.json +7 -7
package/lib/crypto.cjs
CHANGED
|
@@ -1,261 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
3
|
-
var _elliptic = require('elliptic'); var _elliptic2 = _interopRequireDefault(_elliptic);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
var _asn1js = require('asn1.js'); var _asn1js2 = _interopRequireDefault(_asn1js);
|
|
7
|
-
var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
|
|
3
|
+
var _chunkJGXOGWYBcjs = require('./chunk-JGXOGWYB.cjs');
|
|
8
4
|
|
|
9
|
-
var ECPrivateKeyASN = _asn1js2.default.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 = _asn1js2.default.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 = _asn1js2.default.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 _elliptic2.default.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 _elliptic2.default.ec("p256")
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var KeyEncoder = class {
|
|
55
|
-
|
|
56
|
-
|
|
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 (0, _bnjs2.default)(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 (0, _bnjs2.default)(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
5
|
|
|
217
|
-
|
|
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.default.ec("p256");
|
|
236
|
-
const hashedEntropy = _crypto2.default.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 } = _crypto2.default.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
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
exports.genKeys = genKeys;
|
|
6
|
+
exports.genKeys = _chunkJGXOGWYBcjs.genKeys;
|
|
261
7
|
//# sourceMappingURL=crypto.cjs.map
|
package/lib/crypto.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/_work/revault/revault/packages/sdk/lib/crypto.cjs","../src/crypto/utils.ts","../src/crypto/key-encoder.ts"],"names":["elliptic"],"mappings":"AAAA;ACAA,gFAAmB;AACnB,wFAAqB;ADErB;AACA;AEMA,iFAAiB;AACjB,yEAAe;AACf;AAGA,IAAM,gBAAA,EAAkB,gBAAA,CAAK,MAAA,CAAO,cAAA,E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W,MAAM,CAAC,CAAC,CAAC;AAAA,IAC9F,CAAA;AAAA,EACF;AACA,EAAA,MAAM,EAAE,SAAA,EAAW,WAAW,EAAA,EAAI,gBAAA,CAAO,mBAAA,CAAoB,IAAA,EAAM;AAAA,IACjE,UAAA,EAAY,OAAA;AAAA,IACZ,iBAAA,EAAmB,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAQ,MAAM,CAAA;AAAA,IACjD,kBAAA,EAAoB,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAQ,MAAM;AAAA,EACpD,CAAC,CAAA;AACD,EAAA,MAAM,UAAA,EAAY,gBAAA,CAAiB,SAAS,CAAA;AAC5C,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;ADyMA;AACE;AACF,0BAAC","file":"/home/runner/_work/revault/revault/packages/sdk/lib/crypto.cjs","sourcesContent":[null,"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 key\");\n /* v8 ignore stop */\n }\n }\n}\n/* cspell:enable */\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/_work/revault/revault/packages/sdk/lib/crypto.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,4CAAC","file":"/home/runner/_work/revault/revault/packages/sdk/lib/crypto.cjs"}
|
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 key\");\n /* v8 ignore stop */\n }\n }\n}\n/* cspell:enable */\n"],"mappings":";AAAA,OAAO,YAAY;AACnB,OAAOA,eAAc;;;ACSrB,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,cAAc;AAGrB,IAAM,kBAAkB,KAAK,OAAO,gBAAgB,WAAY;AAG9D,QAAM,OAAO;AACb,OACG,IAAI,EACJ;AAAA,IACC,KAAK,IAAI,SAAS,EAAE,IAAI;AAAA,IACxB,KAAK,IAAI,YAAY,EAAE,OAAO;AAAA,IAC9B,KAAK,IAAI,YAAY,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS;AAAA,IACpD,KAAK,IAAI,WAAW,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS;AAAA,EACtD;AACJ,CAAC;AAED,IAAM,mBAAmB,KAAK;AAAA,EAC5B;AAAA;AAAA,EAEA,WAAY;AAGV,UAAM,OAAO;AACb,SACG,IAAI,EACJ;AAAA,MACC,KAAK,IAAI,SAAS,EAAE,IAAI;AAAA,MACxB,KACG,IAAI,qBAAqB,EACzB,IAAI,EACJ,IAAI,KAAK,IAAI,aAAa,EAAE,MAAM,GAAG,KAAK,IAAI,OAAO,EAAE,MAAM,CAAC;AAAA,MACjE,KAAK,IAAI,YAAY,EAAE,OAAO,EAAE,SAAS,eAAe;AAAA,MACxD,KAAK,IAAI,YAAY,EAAE,SAAS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B,OAAO,WAAW,QAAQ,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAC9E,UAAM,UAAU,GAAG,WAAW;AAAA,MAC5B,SAAS,OAAO,KAAK,eAAe,KAAK;AAAA,IAC3C,CAAC;AACD,WAAO;AAAA,MACL,YAAY,OAAO,SAAS,QAAQ,WAAW,KAAK,CAAC,CAAC;AAAA,MACtD,WAAW,OAAO,SAAS,QAAQ,UAAU,KAAK,GAAG,EAAE,WAAW,MAAM,CAAC,CAAC;AAAA,MAC1E,WAAW,iBAAiB,OAAO,SAAS,QAAQ,UAAU,KAAK,GAAG,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/engine.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { L as Logger } from './logger-C-TPbnjv.cjs';
|
|
2
|
-
import { a as EngineOptions, E as Engine } from './types-
|
|
3
|
-
export { A as ApproveRequestParams, m as DecorateWithApiUserAndWorkspaceUnauthenticated, D as DecorateWithDevice, e as DecorateWithDeviceAndOnboarding, k as DecorateWithDeviceAndWorkspaceUnauthenticated, g as DecorateWithWorkspace, j as DecorateWithWorkspaceApiAuthenticated, i as DecorateWithWorkspacePsdAuthenticated, h as DecorateWithWorkspaceUnauthenticated, b as EngineBase, R as RegisterOnboardingDeviceParams, n as WithApiAuth, d as WithApiUser, c as WithDevice, W as WithOnboarding, l as WithPsdAuth, f as WithWorkspace } from './types-
|
|
2
|
+
import { a as EngineOptions, E as Engine } from './types-DEyShR5S.cjs';
|
|
3
|
+
export { A as ApproveRequestParams, m as DecorateWithApiUserAndWorkspaceUnauthenticated, D as DecorateWithDevice, e as DecorateWithDeviceAndOnboarding, k as DecorateWithDeviceAndWorkspaceUnauthenticated, g as DecorateWithWorkspace, j as DecorateWithWorkspaceApiAuthenticated, i as DecorateWithWorkspacePsdAuthenticated, h as DecorateWithWorkspaceUnauthenticated, b as EngineBase, R as RegisterOnboardingDeviceParams, n as WithApiAuth, d as WithApiUser, c as WithDevice, W as WithOnboarding, l as WithPsdAuth, f as WithWorkspace } from './types-DEyShR5S.cjs';
|
|
4
4
|
import { Paginated, CursorPaginated } from '@ledgerhq/revault-api';
|
|
5
5
|
import './types-DJfbanPz.cjs';
|
|
6
|
-
import './
|
|
6
|
+
import './types-Ct-F-l82.cjs';
|
|
7
7
|
import '@trpc/client';
|
|
8
8
|
import '@trpc/server';
|
|
9
9
|
|
package/lib/engine.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { L as Logger } from './logger-C-TPbnjv.js';
|
|
2
|
-
import { a as EngineOptions, E as Engine } from './types-
|
|
3
|
-
export { A as ApproveRequestParams, m as DecorateWithApiUserAndWorkspaceUnauthenticated, D as DecorateWithDevice, e as DecorateWithDeviceAndOnboarding, k as DecorateWithDeviceAndWorkspaceUnauthenticated, g as DecorateWithWorkspace, j as DecorateWithWorkspaceApiAuthenticated, i as DecorateWithWorkspacePsdAuthenticated, h as DecorateWithWorkspaceUnauthenticated, b as EngineBase, R as RegisterOnboardingDeviceParams, n as WithApiAuth, d as WithApiUser, c as WithDevice, W as WithOnboarding, l as WithPsdAuth, f as WithWorkspace } from './types-
|
|
2
|
+
import { a as EngineOptions, E as Engine } from './types-Cp-L-rsW.js';
|
|
3
|
+
export { A as ApproveRequestParams, m as DecorateWithApiUserAndWorkspaceUnauthenticated, D as DecorateWithDevice, e as DecorateWithDeviceAndOnboarding, k as DecorateWithDeviceAndWorkspaceUnauthenticated, g as DecorateWithWorkspace, j as DecorateWithWorkspaceApiAuthenticated, i as DecorateWithWorkspacePsdAuthenticated, h as DecorateWithWorkspaceUnauthenticated, b as EngineBase, R as RegisterOnboardingDeviceParams, n as WithApiAuth, d as WithApiUser, c as WithDevice, W as WithOnboarding, l as WithPsdAuth, f as WithWorkspace } from './types-Cp-L-rsW.js';
|
|
4
4
|
import { Paginated, CursorPaginated } from '@ledgerhq/revault-api';
|
|
5
5
|
import './types-DJfbanPz.js';
|
|
6
|
-
import './
|
|
6
|
+
import './types-Ct-F-l82.js';
|
|
7
7
|
import '@trpc/client';
|
|
8
8
|
import '@trpc/server';
|
|
9
9
|
|
package/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { L as Logger } from './logger-C-TPbnjv.cjs';
|
|
2
|
-
export { R as RevaultApiTRPCClient } from './
|
|
2
|
+
export { R as RevaultApiTRPCClient, a as RouterInputs, b as RouterOutputs } from './types-Ct-F-l82.cjs';
|
|
3
3
|
export * from '@ledgerhq/revault-api';
|
|
4
4
|
import '@trpc/client';
|
|
5
5
|
import '@trpc/server';
|