@twin.org/web 0.0.1-next.42 → 0.0.1-next.43
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/dist/cjs/index.cjs
CHANGED
|
@@ -727,21 +727,16 @@ class Jwk {
|
|
|
727
727
|
*/
|
|
728
728
|
static async fromEd25519Private(privateKey) {
|
|
729
729
|
core.Guards.uint8Array(Jwk._CLASS_NAME, "privateKey", privateKey);
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
return (await jose.importJWK(jwk));
|
|
741
|
-
}
|
|
742
|
-
catch (err) {
|
|
743
|
-
throw new core.GeneralError(Jwk._CLASS_NAME, "jwkImportFailed", undefined, err);
|
|
744
|
-
}
|
|
730
|
+
const publicKey = crypto.Ed25519.publicKeyFromPrivateKey(privateKey);
|
|
731
|
+
const jwk = {
|
|
732
|
+
kty: "OKP",
|
|
733
|
+
use: "enc",
|
|
734
|
+
alg: "EdDSA",
|
|
735
|
+
crv: "Ed25519",
|
|
736
|
+
x: core.Converter.bytesToBase64Url(publicKey),
|
|
737
|
+
d: core.Converter.bytesToBase64Url(privateKey)
|
|
738
|
+
};
|
|
739
|
+
return jwk;
|
|
745
740
|
}
|
|
746
741
|
/**
|
|
747
742
|
* Convert the Ed25519 public key to a crypto key.
|
|
@@ -750,19 +745,14 @@ class Jwk {
|
|
|
750
745
|
*/
|
|
751
746
|
static async fromEd25519Public(publicKey) {
|
|
752
747
|
core.Guards.uint8Array(Jwk._CLASS_NAME, "publicKey", publicKey);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return (await jose.importJWK(jwk));
|
|
762
|
-
}
|
|
763
|
-
catch (err) {
|
|
764
|
-
throw new core.GeneralError(Jwk._CLASS_NAME, "jwkImportFailed", undefined, err);
|
|
765
|
-
}
|
|
748
|
+
const jwk = {
|
|
749
|
+
kty: "OKP",
|
|
750
|
+
use: "sig",
|
|
751
|
+
alg: "EdDSA",
|
|
752
|
+
crv: "Ed25519",
|
|
753
|
+
x: core.Converter.bytesToBase64Url(publicKey)
|
|
754
|
+
};
|
|
755
|
+
return jwk;
|
|
766
756
|
}
|
|
767
757
|
}
|
|
768
758
|
|
|
@@ -781,15 +771,16 @@ class Jws {
|
|
|
781
771
|
* Create a signature.
|
|
782
772
|
* @param privateKey The private key to use.
|
|
783
773
|
* @param hash The hash to sign.
|
|
774
|
+
* @param algOverride An optional algorithm override.
|
|
784
775
|
* @returns The signature.
|
|
785
776
|
*/
|
|
786
|
-
static async create(privateKey, hash) {
|
|
777
|
+
static async create(privateKey, hash, algOverride) {
|
|
787
778
|
core.Guards.defined(Jws._CLASS_NAME, "privateKey", privateKey);
|
|
788
779
|
core.Guards.uint8Array(Jws._CLASS_NAME, "hash", hash);
|
|
789
780
|
try {
|
|
790
781
|
const jws = await new jose.CompactSign(hash)
|
|
791
782
|
.setProtectedHeader({
|
|
792
|
-
alg: privateKey.algorithm.name,
|
|
783
|
+
alg: core.Is.uint8Array(privateKey) ? (algOverride ?? "EdDSA") : privateKey.algorithm.name,
|
|
793
784
|
b64: false,
|
|
794
785
|
crit: ["b64"]
|
|
795
786
|
})
|
|
@@ -949,7 +940,7 @@ class Jwt {
|
|
|
949
940
|
let finalKey = key;
|
|
950
941
|
if (header.alg === "EdDSA" && core.Is.uint8Array(key)) {
|
|
951
942
|
// Jose does not support Ed25519 keys in raw format, so we need to convert it to PKCS8.
|
|
952
|
-
finalKey = await crypto.Ed25519.
|
|
943
|
+
finalKey = await crypto.Ed25519.privateKeyToPkcs8(key);
|
|
953
944
|
}
|
|
954
945
|
return signer.sign(finalKey);
|
|
955
946
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -725,21 +725,16 @@ class Jwk {
|
|
|
725
725
|
*/
|
|
726
726
|
static async fromEd25519Private(privateKey) {
|
|
727
727
|
Guards.uint8Array(Jwk._CLASS_NAME, "privateKey", privateKey);
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
return (await importJWK(jwk));
|
|
739
|
-
}
|
|
740
|
-
catch (err) {
|
|
741
|
-
throw new GeneralError(Jwk._CLASS_NAME, "jwkImportFailed", undefined, err);
|
|
742
|
-
}
|
|
728
|
+
const publicKey = Ed25519.publicKeyFromPrivateKey(privateKey);
|
|
729
|
+
const jwk = {
|
|
730
|
+
kty: "OKP",
|
|
731
|
+
use: "enc",
|
|
732
|
+
alg: "EdDSA",
|
|
733
|
+
crv: "Ed25519",
|
|
734
|
+
x: Converter.bytesToBase64Url(publicKey),
|
|
735
|
+
d: Converter.bytesToBase64Url(privateKey)
|
|
736
|
+
};
|
|
737
|
+
return jwk;
|
|
743
738
|
}
|
|
744
739
|
/**
|
|
745
740
|
* Convert the Ed25519 public key to a crypto key.
|
|
@@ -748,19 +743,14 @@ class Jwk {
|
|
|
748
743
|
*/
|
|
749
744
|
static async fromEd25519Public(publicKey) {
|
|
750
745
|
Guards.uint8Array(Jwk._CLASS_NAME, "publicKey", publicKey);
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return (await importJWK(jwk));
|
|
760
|
-
}
|
|
761
|
-
catch (err) {
|
|
762
|
-
throw new GeneralError(Jwk._CLASS_NAME, "jwkImportFailed", undefined, err);
|
|
763
|
-
}
|
|
746
|
+
const jwk = {
|
|
747
|
+
kty: "OKP",
|
|
748
|
+
use: "sig",
|
|
749
|
+
alg: "EdDSA",
|
|
750
|
+
crv: "Ed25519",
|
|
751
|
+
x: Converter.bytesToBase64Url(publicKey)
|
|
752
|
+
};
|
|
753
|
+
return jwk;
|
|
764
754
|
}
|
|
765
755
|
}
|
|
766
756
|
|
|
@@ -779,15 +769,16 @@ class Jws {
|
|
|
779
769
|
* Create a signature.
|
|
780
770
|
* @param privateKey The private key to use.
|
|
781
771
|
* @param hash The hash to sign.
|
|
772
|
+
* @param algOverride An optional algorithm override.
|
|
782
773
|
* @returns The signature.
|
|
783
774
|
*/
|
|
784
|
-
static async create(privateKey, hash) {
|
|
775
|
+
static async create(privateKey, hash, algOverride) {
|
|
785
776
|
Guards.defined(Jws._CLASS_NAME, "privateKey", privateKey);
|
|
786
777
|
Guards.uint8Array(Jws._CLASS_NAME, "hash", hash);
|
|
787
778
|
try {
|
|
788
779
|
const jws = await new CompactSign(hash)
|
|
789
780
|
.setProtectedHeader({
|
|
790
|
-
alg: privateKey.algorithm.name,
|
|
781
|
+
alg: Is.uint8Array(privateKey) ? (algOverride ?? "EdDSA") : privateKey.algorithm.name,
|
|
791
782
|
b64: false,
|
|
792
783
|
crit: ["b64"]
|
|
793
784
|
})
|
|
@@ -947,7 +938,7 @@ class Jwt {
|
|
|
947
938
|
let finalKey = key;
|
|
948
939
|
if (header.alg === "EdDSA" && Is.uint8Array(key)) {
|
|
949
940
|
// Jose does not support Ed25519 keys in raw format, so we need to convert it to PKCS8.
|
|
950
|
-
finalKey = await Ed25519.
|
|
941
|
+
finalKey = await Ed25519.privateKeyToPkcs8(key);
|
|
951
942
|
}
|
|
952
943
|
return signer.sign(finalKey);
|
|
953
944
|
}
|
|
@@ -15,11 +15,11 @@ export declare class Jwk {
|
|
|
15
15
|
* @param privateKey The private key to use.
|
|
16
16
|
* @returns The crypto key.
|
|
17
17
|
*/
|
|
18
|
-
static fromEd25519Private(privateKey: Uint8Array): Promise<
|
|
18
|
+
static fromEd25519Private(privateKey: Uint8Array): Promise<IJwk>;
|
|
19
19
|
/**
|
|
20
20
|
* Convert the Ed25519 public key to a crypto key.
|
|
21
21
|
* @param publicKey The private key to use.
|
|
22
22
|
* @returns The crypto key.
|
|
23
23
|
*/
|
|
24
|
-
static fromEd25519Public(publicKey: Uint8Array): Promise<
|
|
24
|
+
static fromEd25519Public(publicKey: Uint8Array): Promise<IJwk>;
|
|
25
25
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
1
2
|
/**
|
|
2
3
|
* Class to handle JSON Web Signatures.
|
|
3
4
|
*/
|
|
@@ -6,9 +7,10 @@ export declare class Jws {
|
|
|
6
7
|
* Create a signature.
|
|
7
8
|
* @param privateKey The private key to use.
|
|
8
9
|
* @param hash The hash to sign.
|
|
10
|
+
* @param algOverride An optional algorithm override.
|
|
9
11
|
* @returns The signature.
|
|
10
12
|
*/
|
|
11
|
-
static create(privateKey:
|
|
13
|
+
static create(privateKey: JwkCryptoKey, hash: Uint8Array, algOverride?: string): Promise<string>;
|
|
12
14
|
/**
|
|
13
15
|
* Verify a signature.
|
|
14
16
|
* @param jws The signature to verify.
|
|
@@ -16,5 +18,5 @@ export declare class Jws {
|
|
|
16
18
|
* @param hash The hash to verify.
|
|
17
19
|
* @returns True if the signature was verified.
|
|
18
20
|
*/
|
|
19
|
-
static verify(jws: string, publicKey:
|
|
21
|
+
static verify(jws: string, publicKey: JwkCryptoKey, hash: Uint8Array): Promise<boolean>;
|
|
20
22
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -38,7 +38,7 @@ The crypto key.
|
|
|
38
38
|
|
|
39
39
|
### fromEd25519Private()
|
|
40
40
|
|
|
41
|
-
> `static` **fromEd25519Private**(`privateKey`): `Promise
|
|
41
|
+
> `static` **fromEd25519Private**(`privateKey`): `Promise`\<[`IJwk`](../interfaces/IJwk.md)\>
|
|
42
42
|
|
|
43
43
|
Convert the Ed25519 private key to a crypto key.
|
|
44
44
|
|
|
@@ -52,7 +52,7 @@ The private key to use.
|
|
|
52
52
|
|
|
53
53
|
#### Returns
|
|
54
54
|
|
|
55
|
-
`Promise
|
|
55
|
+
`Promise`\<[`IJwk`](../interfaces/IJwk.md)\>
|
|
56
56
|
|
|
57
57
|
The crypto key.
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ The crypto key.
|
|
|
60
60
|
|
|
61
61
|
### fromEd25519Public()
|
|
62
62
|
|
|
63
|
-
> `static` **fromEd25519Public**(`publicKey`): `Promise
|
|
63
|
+
> `static` **fromEd25519Public**(`publicKey`): `Promise`\<[`IJwk`](../interfaces/IJwk.md)\>
|
|
64
64
|
|
|
65
65
|
Convert the Ed25519 public key to a crypto key.
|
|
66
66
|
|
|
@@ -74,6 +74,6 @@ The private key to use.
|
|
|
74
74
|
|
|
75
75
|
#### Returns
|
|
76
76
|
|
|
77
|
-
`Promise
|
|
77
|
+
`Promise`\<[`IJwk`](../interfaces/IJwk.md)\>
|
|
78
78
|
|
|
79
79
|
The crypto key.
|
|
@@ -16,7 +16,7 @@ Class to handle JSON Web Signatures.
|
|
|
16
16
|
|
|
17
17
|
### create()
|
|
18
18
|
|
|
19
|
-
> `static` **create**(`privateKey`, `hash`): `Promise`\<`string`\>
|
|
19
|
+
> `static` **create**(`privateKey`, `hash`, `algOverride`?): `Promise`\<`string`\>
|
|
20
20
|
|
|
21
21
|
Create a signature.
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ Create a signature.
|
|
|
24
24
|
|
|
25
25
|
##### privateKey
|
|
26
26
|
|
|
27
|
-
`
|
|
27
|
+
[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
28
28
|
|
|
29
29
|
The private key to use.
|
|
30
30
|
|
|
@@ -34,6 +34,12 @@ The private key to use.
|
|
|
34
34
|
|
|
35
35
|
The hash to sign.
|
|
36
36
|
|
|
37
|
+
##### algOverride?
|
|
38
|
+
|
|
39
|
+
`string`
|
|
40
|
+
|
|
41
|
+
An optional algorithm override.
|
|
42
|
+
|
|
37
43
|
#### Returns
|
|
38
44
|
|
|
39
45
|
`Promise`\<`string`\>
|
|
@@ -58,7 +64,7 @@ The signature to verify.
|
|
|
58
64
|
|
|
59
65
|
##### publicKey
|
|
60
66
|
|
|
61
|
-
`
|
|
67
|
+
[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
62
68
|
|
|
63
69
|
The public key to verify the signature with.
|
|
64
70
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/web",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.43",
|
|
4
4
|
"description": "Contains classes for use with web operations",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.1-next.
|
|
18
|
-
"@twin.org/crypto": "0.0.1-next.
|
|
17
|
+
"@twin.org/core": "0.0.1-next.43",
|
|
18
|
+
"@twin.org/crypto": "0.0.1-next.43",
|
|
19
19
|
"@twin.org/nameof": "next",
|
|
20
20
|
"jose": "6.0.8"
|
|
21
21
|
},
|