@sphereon/ssi-sdk-ext.key-utils 0.13.1-next.7 → 0.13.1-next.9
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HashAlgorithm } from '../digest-methods';
|
|
2
|
-
import { JWK } from '../types';
|
|
2
|
+
import { JWK, KeyVisibility } from '../types';
|
|
3
3
|
import { RSAEncryptionSchemes, RSASignatureSchemes } from './rsa-key';
|
|
4
4
|
export declare class RSASigner {
|
|
5
5
|
private readonly hashAlgorithm;
|
|
@@ -14,11 +14,12 @@ export declare class RSASigner {
|
|
|
14
14
|
constructor(key: string | JWK, opts?: {
|
|
15
15
|
hashAlgorithm?: HashAlgorithm;
|
|
16
16
|
scheme?: RSAEncryptionSchemes | RSASignatureSchemes;
|
|
17
|
+
visibility?: KeyVisibility;
|
|
17
18
|
});
|
|
18
19
|
private getImportParams;
|
|
19
20
|
private getKey;
|
|
20
21
|
private bufferToString;
|
|
21
|
-
sign(data:
|
|
22
|
-
verify(data: string | Uint8Array, signature: string
|
|
22
|
+
sign(data: Uint8Array): Promise<string>;
|
|
23
|
+
verify(data: string | Uint8Array, signature: string): Promise<boolean>;
|
|
23
24
|
}
|
|
24
25
|
//# sourceMappingURL=rsa-signer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa-signer.d.ts","sourceRoot":"","sources":["../../src/x509/rsa-signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"rsa-signer.d.ts","sourceRoot":"","sources":["../../src/x509/rsa-signer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAA4B,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAG/F,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;IAEzB,OAAO,CAAC,GAAG,CAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IAEnE;;;;OAIG;gBAED,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,aAAa,CAAC;QAAC,MAAM,CAAC,EAAE,oBAAoB,GAAG,mBAAmB,CAAC;QAAC,UAAU,CAAC,EAAE,aAAa,CAAA;KAAE;IAY3H,OAAO,CAAC,eAAe;YAQT,MAAM;IAOpB,OAAO,CAAC,cAAc;IAKT,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAYvC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAOpF"}
|
package/dist/x509/rsa-signer.js
CHANGED
|
@@ -49,7 +49,7 @@ class RSASigner {
|
|
|
49
49
|
constructor(key, opts) {
|
|
50
50
|
var _a, _b;
|
|
51
51
|
if (typeof key === 'string') {
|
|
52
|
-
this.jwk = (0, x509_utils_1.PEMToJwk)(key);
|
|
52
|
+
this.jwk = (0, x509_utils_1.PEMToJwk)(key, opts === null || opts === void 0 ? void 0 : opts.visibility);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
this.jwk = key;
|
|
@@ -78,7 +78,7 @@ class RSASigner {
|
|
|
78
78
|
}
|
|
79
79
|
sign(data) {
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const input =
|
|
81
|
+
const input = data;
|
|
82
82
|
const key = yield this.getKey();
|
|
83
83
|
const signature = this.bufferToString(yield isomorphic_webcrypto_1.default.subtle.sign(this.getImportParams(), key, input));
|
|
84
84
|
if (!signature) {
|
|
@@ -90,8 +90,7 @@ class RSASigner {
|
|
|
90
90
|
}
|
|
91
91
|
verify(data, signature) {
|
|
92
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const
|
|
94
|
-
const jws = sig.includes('.') ? sig.split('.')[2] : sig;
|
|
93
|
+
const jws = signature.includes('.') ? signature.split('.')[2] : signature;
|
|
95
94
|
const input = typeof data == 'string' ? u8a.fromString(data, 'utf-8') : data;
|
|
96
95
|
const verificationResult = yield isomorphic_webcrypto_1.default.subtle.verify(this.getImportParams(), yield this.getKey(), u8a.fromString(jws, 'base64url'), input);
|
|
97
96
|
return verificationResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa-signer.js","sourceRoot":"","sources":["../../src/x509/rsa-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAkC;AAClC,0FAAmD;AAGnD,uCAA+F;AAC/F,6CAAuC;AAEvC,MAAa,SAAS;IAOpB;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"rsa-signer.js","sourceRoot":"","sources":["../../src/x509/rsa-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAkC;AAClC,0FAAmD;AAGnD,uCAA+F;AAC/F,6CAAuC;AAEvC,MAAa,SAAS;IAOpB;;;;OAIG;IACH,YACE,GAAiB,EACjB,IAAyH;;QAEzH,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAA,qBAAQ,EAAC,GAAG,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAC,CAAA;SAC3C;aAAM;YACL,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;SACf;QAED,IAAI,CAAC,aAAa,GAAG,MAAA,IAAI,aA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B,OAAO,SAAS,CAAA;QAClB,CAAC;KAAA;IAEY,MAAM,CAAC,IAAyB,EAAE,SAAiB;;YAC9D,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YAEzE,MAAM,KAAK,GAAG,OAAO,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC5E,MAAM,kBAAkB,GAAG,MAAM,8BAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,KAAK,CAAC,CAAA;YAC3I,OAAO,kBAAkB,CAAA;QAC3B,CAAC;KAAA;CACF;AAjED,8BAiEC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.key-utils",
|
|
3
3
|
"description": "Sphereon SSI-SDK plugin for key creation.",
|
|
4
|
-
"version": "0.13.1-next.
|
|
4
|
+
"version": "0.13.1-next.9+8f58f23",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"DID",
|
|
48
48
|
"Veramo"
|
|
49
49
|
],
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "8f58f2308bc0dd612d1bb47b5ae05e8b67cf2efb"
|
|
51
51
|
}
|
package/src/x509/rsa-signer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as u8a from 'uint8arrays'
|
|
2
2
|
import crypto from '@sphereon/isomorphic-webcrypto'
|
|
3
3
|
import { HashAlgorithm } from '../digest-methods'
|
|
4
|
-
import { JWK } from '../types'
|
|
4
|
+
import { JWK, KeyVisibility } from '../types'
|
|
5
5
|
import { cryptoSubtleImportRSAKey, RSAEncryptionSchemes, RSASignatureSchemes } from './rsa-key'
|
|
6
6
|
import { PEMToJwk } from './x509-utils'
|
|
7
7
|
|
|
@@ -17,9 +17,12 @@ export class RSASigner {
|
|
|
17
17
|
* @param key Either in PEM or JWK format (no raw hex keys here!)
|
|
18
18
|
* @param opts The algorithm and signature/encryption schemes
|
|
19
19
|
*/
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
key: string | JWK,
|
|
22
|
+
opts?: { hashAlgorithm?: HashAlgorithm; scheme?: RSAEncryptionSchemes | RSASignatureSchemes; visibility?: KeyVisibility }
|
|
23
|
+
) {
|
|
21
24
|
if (typeof key === 'string') {
|
|
22
|
-
this.jwk = PEMToJwk(key)
|
|
25
|
+
this.jwk = PEMToJwk(key, opts?.visibility)
|
|
23
26
|
} else {
|
|
24
27
|
this.jwk = key
|
|
25
28
|
}
|
|
@@ -48,8 +51,8 @@ export class RSASigner {
|
|
|
48
51
|
return u8a.toString(uint8Array, 'base64url') // Needs to be base64url for JsonWebSignature2020. Don't change!
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
public async sign(data:
|
|
52
|
-
const input =
|
|
54
|
+
public async sign(data: Uint8Array): Promise<string> {
|
|
55
|
+
const input = data
|
|
53
56
|
const key = await this.getKey()
|
|
54
57
|
const signature = this.bufferToString(await crypto.subtle.sign(this.getImportParams(), key, input))
|
|
55
58
|
if (!signature) {
|
|
@@ -60,9 +63,8 @@ export class RSASigner {
|
|
|
60
63
|
return signature
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
public async verify(data: string | Uint8Array, signature: string
|
|
64
|
-
const
|
|
65
|
-
const jws = sig.includes('.') ? sig.split('.')[2] : sig
|
|
66
|
+
public async verify(data: string | Uint8Array, signature: string): Promise<boolean> {
|
|
67
|
+
const jws = signature.includes('.') ? signature.split('.')[2] : signature
|
|
66
68
|
|
|
67
69
|
const input = typeof data == 'string' ? u8a.fromString(data, 'utf-8') : data
|
|
68
70
|
const verificationResult = await crypto.subtle.verify(this.getImportParams(), await this.getKey(), u8a.fromString(jws, 'base64url'), input)
|