@sphereon/ssi-sdk-ext.key-utils 0.13.1-unstable.3 → 0.14.0

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,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(key: string | JWK, opts?: { hashAlgorithm?: HashAlgorithm; scheme?: RSAEncryptionSchemes | RSASignatureSchemes }) {
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: string | Uint8Array): Promise<string> {
52
- const input = typeof data === 'string' ? u8a.fromString(data, 'utf-8') : data
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 | Uint8Array): Promise<boolean> {
64
- const sig = typeof signature === 'string' ? signature : u8a.toString(signature, 'base64url')
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)