@lindorm/ec 0.1.0 → 0.1.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/CHANGELOG.md +12 -0
- package/dist/classes/EcKit.d.ts +0 -1
- package/dist/classes/EcKit.d.ts.map +1 -1
- package/dist/classes/EcKit.js +6 -6
- package/dist/classes/EcKit.js.map +1 -1
- package/dist/types/ec-kit.d.ts +8 -11
- package/dist/types/ec-kit.d.ts.map +1 -1
- package/dist/utils/private/ec-signature.d.ts +3 -3
- package/dist/utils/private/ec-signature.d.ts.map +1 -1
- package/dist/utils/private/ec-signature.js +20 -18
- package/dist/utils/private/ec-signature.js.map +1 -1
- package/dist/utils/private/get-key.d.ts +4 -0
- package/dist/utils/private/get-key.d.ts.map +1 -0
- package/dist/utils/private/get-key.js +21 -0
- package/dist/utils/private/get-key.js.map +1 -0
- package/dist/utils/private/map-algorithm.d.ts +4 -0
- package/dist/utils/private/map-algorithm.d.ts.map +1 -0
- package/dist/utils/private/map-algorithm.js +19 -0
- package/dist/utils/private/map-algorithm.js.map +1 -0
- package/dist/utils/private/raw.d.ts +5 -0
- package/dist/utils/private/raw.d.ts.map +1 -0
- package/dist/utils/private/raw.js +72 -0
- package/dist/utils/private/raw.js.map +1 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.2](https://github.com/lindorm-io/monorepo/compare/@lindorm/ec@0.1.1...@lindorm/ec@0.1.2) (2024-05-20)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @lindorm/ec
|
|
9
|
+
|
|
10
|
+
## [0.1.1](https://github.com/lindorm-io/monorepo/compare/@lindorm/ec@0.1.0...@lindorm/ec@0.1.1) (2024-05-19)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- align with kryptos changes ([344c4e2](https://github.com/lindorm-io/monorepo/commit/344c4e2fad07e66c91f7e0820bfc929c1f8ffcab))
|
|
15
|
+
- rename interfaces ([3b1f457](https://github.com/lindorm-io/monorepo/commit/3b1f45736f88b8c2d4481cbeca6da87bf8443bde))
|
|
16
|
+
- simplify interfaces with kryptos metadata ([c4075d2](https://github.com/lindorm-io/monorepo/commit/c4075d2e133c2fe0a1fafa548da68db34b3407c6))
|
|
17
|
+
|
|
6
18
|
# 0.1.0 (2024-05-12)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/dist/classes/EcKit.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EcKit.d.ts","sourceRoot":"","sources":["../../src/classes/EcKit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EcKit.d.ts","sourceRoot":"","sources":["../../src/classes/EcKit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAqB,MAAM,UAAU,CAAC;AAO3D,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;gBAElB,OAAO,EAAE,YAAY;IAUjC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQ1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;IAShD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAQrD"}
|
package/dist/classes/EcKit.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EcKit = void 0;
|
|
4
|
+
const kryptos_1 = require("@lindorm/kryptos");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
4
6
|
const ec_signature_1 = require("../utils/private/ec-signature");
|
|
5
7
|
class EcKit {
|
|
6
|
-
algorithm;
|
|
7
8
|
format;
|
|
8
9
|
kryptos;
|
|
9
10
|
constructor(options) {
|
|
10
|
-
this.
|
|
11
|
-
|
|
11
|
+
this.format = options.format ?? "base64";
|
|
12
|
+
if (!kryptos_1.Kryptos.isEc(options.kryptos)) {
|
|
13
|
+
throw new errors_1.EcError("Invalid Kryptos instance");
|
|
14
|
+
}
|
|
12
15
|
this.kryptos = options.kryptos;
|
|
13
16
|
}
|
|
14
17
|
sign(data) {
|
|
15
18
|
return (0, ec_signature_1._createEcSignature)({
|
|
16
|
-
algorithm: this.algorithm,
|
|
17
19
|
data,
|
|
18
20
|
format: this.format,
|
|
19
21
|
kryptos: this.kryptos,
|
|
@@ -21,7 +23,6 @@ class EcKit {
|
|
|
21
23
|
}
|
|
22
24
|
verify(data, signature) {
|
|
23
25
|
return (0, ec_signature_1._verifyEcSignature)({
|
|
24
|
-
algorithm: this.algorithm,
|
|
25
26
|
data,
|
|
26
27
|
format: this.format,
|
|
27
28
|
kryptos: this.kryptos,
|
|
@@ -30,7 +31,6 @@ class EcKit {
|
|
|
30
31
|
}
|
|
31
32
|
assert(data, signature) {
|
|
32
33
|
return (0, ec_signature_1._assertEcSignature)({
|
|
33
|
-
algorithm: this.algorithm,
|
|
34
34
|
data,
|
|
35
35
|
format: this.format,
|
|
36
36
|
kryptos: this.kryptos,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EcKit.js","sourceRoot":"","sources":["../../src/classes/EcKit.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EcKit.js","sourceRoot":"","sources":["../../src/classes/EcKit.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AACvD,sCAAoC;AAEpC,gEAIuC;AAEvC,MAAa,KAAK;IACC,MAAM,CAAoB;IAC1B,OAAO,CAAa;IAErC,YAAmB,OAAqB;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC;QAEzC,IAAI,CAAC,iBAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,gBAAO,CAAC,0BAA0B,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAEM,IAAI,CAAC,IAAY;QACtB,OAAO,IAAA,iCAAkB,EAAC;YACxB,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,IAAY,EAAE,SAAiB;QAC3C,OAAO,IAAA,iCAAkB,EAAC;YACxB,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,IAAY,EAAE,SAAiB;QAC3C,OAAO,IAAA,iCAAkB,EAAC;YACxB,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS;SACV,CAAC,CAAC;IACL,CAAC;CACF;AAvCD,sBAuCC"}
|
package/dist/types/ec-kit.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type EcSignatureFormat =
|
|
1
|
+
import { IKryptos, IKryptosEc } from "@lindorm/kryptos";
|
|
2
|
+
import { BufferFormat } from "@lindorm/types";
|
|
3
|
+
export type EcSignatureFormat = BufferFormat | "raw";
|
|
4
4
|
export type CreateEcSignatureOptions = {
|
|
5
|
-
algorithm?: EcSignatureAlgorithm;
|
|
6
5
|
data: string;
|
|
7
|
-
format
|
|
8
|
-
kryptos:
|
|
6
|
+
format: EcSignatureFormat;
|
|
7
|
+
kryptos: IKryptosEc;
|
|
9
8
|
};
|
|
10
9
|
export type VerifyEcSignatureOptions = {
|
|
11
|
-
algorithm?: EcSignatureAlgorithm;
|
|
12
10
|
data: string;
|
|
13
|
-
format
|
|
11
|
+
format: EcSignatureFormat;
|
|
12
|
+
kryptos: IKryptosEc;
|
|
14
13
|
signature: string;
|
|
15
|
-
kryptos: Kryptos;
|
|
16
14
|
};
|
|
17
15
|
export type EcKitOptions = {
|
|
18
|
-
algorithm?: EcSignatureAlgorithm;
|
|
19
16
|
format?: EcSignatureFormat;
|
|
20
|
-
kryptos:
|
|
17
|
+
kryptos: IKryptos;
|
|
21
18
|
};
|
|
22
19
|
//# sourceMappingURL=ec-kit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec-kit.d.ts","sourceRoot":"","sources":["../../src/types/ec-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ec-kit.d.ts","sourceRoot":"","sources":["../../src/types/ec-kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,KAAK,CAAC;AAErD,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateEcSignatureOptions, VerifyEcSignatureOptions } from "../../types/ec-kit";
|
|
2
|
-
export declare const _createEcSignature: ({
|
|
3
|
-
export declare const _verifyEcSignature: ({
|
|
4
|
-
export declare const _assertEcSignature: ({
|
|
2
|
+
export declare const _createEcSignature: ({ data, format, kryptos }: CreateEcSignatureOptions) => string;
|
|
3
|
+
export declare const _verifyEcSignature: ({ data, format, kryptos, signature, }: VerifyEcSignatureOptions) => boolean;
|
|
4
|
+
export declare const _assertEcSignature: ({ data, format, kryptos, signature, }: VerifyEcSignatureOptions) => void;
|
|
5
5
|
//# sourceMappingURL=ec-signature.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec-signature.d.ts","sourceRoot":"","sources":["../../../src/utils/private/ec-signature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ec-signature.d.ts","sourceRoot":"","sources":["../../../src/utils/private/ec-signature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAKxF,eAAO,MAAM,kBAAkB,8BAA+B,wBAAwB,KAAG,MAQxF,CAAC;AAEF,eAAO,MAAM,kBAAkB,0CAK5B,wBAAwB,KAAG,OAa7B,CAAC;AAEF,eAAO,MAAM,kBAAkB,0CAK5B,wBAAwB,KAAG,IAG7B,CAAC"}
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._assertEcSignature = exports._verifyEcSignature = exports._createEcSignature = void 0;
|
|
4
|
-
const kryptos_1 = require("@lindorm/kryptos");
|
|
5
4
|
const crypto_1 = require("crypto");
|
|
6
5
|
const errors_1 = require("../../errors");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const get_key_1 = require("./get-key");
|
|
7
|
+
const map_algorithm_1 = require("./map-algorithm");
|
|
8
|
+
const raw_1 = require("./raw");
|
|
9
|
+
const _createEcSignature = ({ data, format, kryptos }) => {
|
|
10
|
+
const der = (0, crypto_1.createSign)((0, map_algorithm_1._mapEcAlgorithm)(kryptos)).update(data).end().sign((0, get_key_1._getSignKey)(kryptos));
|
|
11
|
+
if (format === "raw") {
|
|
12
|
+
return (0, raw_1._derToRaw)(kryptos, der).toString("base64url");
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
if (!privateKey) {
|
|
13
|
-
throw new errors_1.EcError("Missing private key");
|
|
14
|
-
}
|
|
15
|
-
return (0, crypto_1.createSign)(algorithm).update(data).end().sign(privateKey, format);
|
|
14
|
+
return der.toString(format);
|
|
16
15
|
};
|
|
17
16
|
exports._createEcSignature = _createEcSignature;
|
|
18
|
-
const _verifyEcSignature = ({
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const _verifyEcSignature = ({ data, format, kryptos, signature, }) => {
|
|
18
|
+
let der;
|
|
19
|
+
if (format === "raw") {
|
|
20
|
+
der = (0, raw_1._rawToDer)(kryptos, Buffer.from(signature, "base64url"));
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new errors_1.EcError("Missing private key");
|
|
22
|
+
else {
|
|
23
|
+
der = Buffer.from(signature, format);
|
|
25
24
|
}
|
|
26
|
-
return (0, crypto_1.createVerify)(
|
|
25
|
+
return (0, crypto_1.createVerify)((0, map_algorithm_1._mapEcAlgorithm)(kryptos))
|
|
26
|
+
.update(data)
|
|
27
|
+
.end()
|
|
28
|
+
.verify((0, get_key_1._getVerifyKey)(kryptos), der);
|
|
27
29
|
};
|
|
28
30
|
exports._verifyEcSignature = _verifyEcSignature;
|
|
29
|
-
const _assertEcSignature = ({
|
|
30
|
-
if ((0, exports._verifyEcSignature)({
|
|
31
|
+
const _assertEcSignature = ({ data, format, kryptos, signature, }) => {
|
|
32
|
+
if ((0, exports._verifyEcSignature)({ data, format, kryptos, signature }))
|
|
31
33
|
return;
|
|
32
34
|
throw new errors_1.EcError("Invalid signature");
|
|
33
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ec-signature.js","sourceRoot":"","sources":["../../../src/utils/private/ec-signature.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ec-signature.js","sourceRoot":"","sources":["../../../src/utils/private/ec-signature.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAClD,yCAAuC;AAEvC,uCAAuD;AACvD,mDAAkD;AAClD,+BAA6C;AAEtC,MAAM,kBAAkB,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAA4B,EAAU,EAAE;IAChG,MAAM,GAAG,GAAG,IAAA,mBAAU,EAAC,IAAA,+BAAe,EAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC,CAAC;IAE/F,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,IAAA,eAAS,EAAC,OAAO,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B;AAEK,MAAM,kBAAkB,GAAG,CAAC,EACjC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,GACgB,EAAW,EAAE;IACtC,IAAI,GAAW,CAAC;IAEhB,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,GAAG,GAAG,IAAA,eAAS,EAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,IAAA,qBAAY,EAAC,IAAA,+BAAe,EAAC,OAAO,CAAC,CAAC;SAC1C,MAAM,CAAC,IAAI,CAAC;SACZ,GAAG,EAAE;SACL,MAAM,CAAC,IAAA,uBAAa,EAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC,CAAC;AAlBW,QAAA,kBAAkB,sBAkB7B;AAEK,MAAM,kBAAkB,GAAG,CAAC,EACjC,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,GACgB,EAAQ,EAAE;IACnC,IAAI,IAAA,0BAAkB,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QAAE,OAAO;IACrE,MAAM,IAAI,gBAAO,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC,CAAC;AARW,QAAA,kBAAkB,sBAQ7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-key.d.ts","sourceRoot":"","sources":["../../../src/utils/private/get-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,WAAW,YAAa,UAAU,KAAG,MAQjD,CAAC;AAEF,eAAO,MAAM,aAAa,YAAa,UAAU,KAAG,MAQnD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._getVerifyKey = exports._getSignKey = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const _getSignKey = (kryptos) => {
|
|
6
|
+
const { privateKey } = kryptos.export("pem");
|
|
7
|
+
if (!privateKey) {
|
|
8
|
+
throw new errors_1.EcError("Missing private key");
|
|
9
|
+
}
|
|
10
|
+
return privateKey;
|
|
11
|
+
};
|
|
12
|
+
exports._getSignKey = _getSignKey;
|
|
13
|
+
const _getVerifyKey = (kryptos) => {
|
|
14
|
+
const { publicKey } = kryptos.export("pem");
|
|
15
|
+
if (!publicKey) {
|
|
16
|
+
throw new errors_1.EcError("Missing private key");
|
|
17
|
+
}
|
|
18
|
+
return publicKey;
|
|
19
|
+
};
|
|
20
|
+
exports._getVerifyKey = _getVerifyKey;
|
|
21
|
+
//# sourceMappingURL=get-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-key.js","sourceRoot":"","sources":["../../../src/utils/private/get-key.ts"],"names":[],"mappings":";;;AACA,yCAAuC;AAEhC,MAAM,WAAW,GAAG,CAAC,OAAmB,EAAU,EAAE;IACzD,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE7C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,gBAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AARW,QAAA,WAAW,eAQtB;AAEK,MAAM,aAAa,GAAG,CAAC,OAAmB,EAAU,EAAE;IAC3D,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE5C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,gBAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-algorithm.d.ts","sourceRoot":"","sources":["../../../src/utils/private/map-algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,eAAe,YAAa,UAAU,KAAG,YAUrD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._mapEcAlgorithm = void 0;
|
|
4
|
+
const kryptos_1 = require("@lindorm/kryptos");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const _mapEcAlgorithm = (kryptos) => {
|
|
7
|
+
if (!kryptos_1.Kryptos.isEc(kryptos)) {
|
|
8
|
+
throw new errors_1.EcError("Invalid kryptos type", { debug: { kryptos } });
|
|
9
|
+
}
|
|
10
|
+
if (kryptos.algorithm.endsWith("256"))
|
|
11
|
+
return "SHA256";
|
|
12
|
+
if (kryptos.algorithm.endsWith("384"))
|
|
13
|
+
return "SHA384";
|
|
14
|
+
if (kryptos.algorithm.endsWith("512"))
|
|
15
|
+
return "SHA512";
|
|
16
|
+
throw new errors_1.EcError("Unsupported EC algorithm", { debug: { kryptos } });
|
|
17
|
+
};
|
|
18
|
+
exports._mapEcAlgorithm = _mapEcAlgorithm;
|
|
19
|
+
//# sourceMappingURL=map-algorithm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-algorithm.js","sourceRoot":"","sources":["../../../src/utils/private/map-algorithm.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AAEvD,yCAAuC;AAEhC,MAAM,eAAe,GAAG,CAAC,OAAmB,EAAgB,EAAE;IACnE,IAAI,CAAC,iBAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,gBAAO,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IAEvD,MAAM,IAAI,gBAAO,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC,CAAC;AAVW,QAAA,eAAe,mBAU1B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IKryptosEc } from "@lindorm/kryptos";
|
|
3
|
+
export declare const _derToRaw: (kryptos: IKryptosEc, derSignature: Buffer) => Buffer;
|
|
4
|
+
export declare const _rawToDer: (kryptos: IKryptosEc, rawSignature: Buffer) => Buffer;
|
|
5
|
+
//# sourceMappingURL=raw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../../src/utils/private/raw.ts"],"names":[],"mappings":";AAAA,OAAO,EAAW,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQvD,eAAO,MAAM,SAAS,YAAa,UAAU,gBAAgB,MAAM,KAAG,MA2CrE,CAAC;AAEF,eAAO,MAAM,SAAS,YAAa,UAAU,gBAAgB,MAAM,KAAG,MA8BrE,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._rawToDer = exports._derToRaw = void 0;
|
|
4
|
+
const KEY_SIZES = {
|
|
5
|
+
"P-256": 32,
|
|
6
|
+
"P-384": 48,
|
|
7
|
+
"P-521": 66,
|
|
8
|
+
};
|
|
9
|
+
const _derToRaw = (kryptos, derSignature) => {
|
|
10
|
+
const keySize = KEY_SIZES[kryptos.curve];
|
|
11
|
+
if (derSignature[0] !== 0x30) {
|
|
12
|
+
throw new Error("Invalid DER format");
|
|
13
|
+
}
|
|
14
|
+
let position = 2;
|
|
15
|
+
const lengthByte = derSignature[1];
|
|
16
|
+
if (lengthByte > 0x80) {
|
|
17
|
+
const lengthBytesCount = lengthByte & 0x7f;
|
|
18
|
+
position += lengthBytesCount;
|
|
19
|
+
}
|
|
20
|
+
function getInteger() {
|
|
21
|
+
if (derSignature[position] !== 0x02) {
|
|
22
|
+
throw new Error("Expected integer");
|
|
23
|
+
}
|
|
24
|
+
const length = derSignature[position + 1];
|
|
25
|
+
position += 2;
|
|
26
|
+
const value = derSignature.subarray(position, position + length);
|
|
27
|
+
position += length;
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
const r = getInteger();
|
|
31
|
+
const s = getInteger();
|
|
32
|
+
const truncatedR = r.length > keySize ? r.subarray(r.length - keySize) : r;
|
|
33
|
+
const truncatedS = s.length > keySize ? s.subarray(s.length - keySize) : s;
|
|
34
|
+
const paddedR = Buffer.concat([
|
|
35
|
+
Buffer.alloc(keySize - truncatedR.length, 0),
|
|
36
|
+
truncatedR,
|
|
37
|
+
]);
|
|
38
|
+
const paddedS = Buffer.concat([
|
|
39
|
+
Buffer.alloc(keySize - truncatedS.length, 0),
|
|
40
|
+
truncatedS,
|
|
41
|
+
]);
|
|
42
|
+
return Buffer.concat([paddedR, paddedS]);
|
|
43
|
+
};
|
|
44
|
+
exports._derToRaw = _derToRaw;
|
|
45
|
+
const _rawToDer = (kryptos, rawSignature) => {
|
|
46
|
+
const keySize = KEY_SIZES[kryptos.curve];
|
|
47
|
+
if (rawSignature.length !== 2 * keySize) {
|
|
48
|
+
throw new Error("Invalid raw signature length");
|
|
49
|
+
}
|
|
50
|
+
const r = rawSignature.subarray(0, keySize);
|
|
51
|
+
const s = rawSignature.subarray(keySize);
|
|
52
|
+
function toDERFormat(value) {
|
|
53
|
+
let pos = 0;
|
|
54
|
+
while (pos < value.length && value[pos] === 0) {
|
|
55
|
+
pos++;
|
|
56
|
+
}
|
|
57
|
+
const subarray = value.subarray(pos);
|
|
58
|
+
if (subarray[0] >= 0x80) {
|
|
59
|
+
return Buffer.concat([Buffer.from([0x02, subarray.length + 1, 0x00]), subarray]);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return Buffer.concat([Buffer.from([0x02, subarray.length]), subarray]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const derR = toDERFormat(r);
|
|
66
|
+
const derS = toDERFormat(s);
|
|
67
|
+
const sequenceLength = derR.length + derS.length;
|
|
68
|
+
const lengthByte = sequenceLength < 128 ? [sequenceLength] : [0x81, sequenceLength];
|
|
69
|
+
return Buffer.concat([Buffer.from([0x30, ...lengthByte]), derR, derS]);
|
|
70
|
+
};
|
|
71
|
+
exports._rawToDer = _rawToDer;
|
|
72
|
+
//# sourceMappingURL=raw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw.js","sourceRoot":"","sources":["../../../src/utils/private/raw.ts"],"names":[],"mappings":";;;AAEA,MAAM,SAAS,GAAG;IAChB,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;CACZ,CAAC;AAEK,MAAM,SAAS,GAAG,CAAC,OAAmB,EAAE,YAAoB,EAAU,EAAE;IAC7E,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,KAAgB,CAAC,CAAC;IAEpD,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,CAAC;IAGjB,MAAM,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,UAAU,GAAG,IAAI,EAAE,CAAC;QACtB,MAAM,gBAAgB,GAAG,UAAU,GAAG,IAAI,CAAC;QAC3C,QAAQ,IAAI,gBAAgB,CAAC;IAC/B,CAAC;IAED,SAAS,UAAU;QACjB,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;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CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAEpF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACzE,CAAC,CAAC;AA9BW,QAAA,SAAS,aA8BpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lindorm/ec",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"author": "Jonn Nilsson",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,11 @@
|
|
|
26
26
|
"update": "ncu -u"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@lindorm/errors": "^0.1.
|
|
30
|
-
"@lindorm/kryptos": "^0.
|
|
29
|
+
"@lindorm/errors": "^0.1.5",
|
|
30
|
+
"@lindorm/kryptos": "^0.3.1"
|
|
31
31
|
},
|
|
32
|
-
"
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@lindorm/types": "^0.1.4"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "b2bcea52f09a87f312028c18b12dcb5632ffaf35"
|
|
33
36
|
}
|