@sphereon/ssi-sdk-ext.x509-utils 0.28.1-feature.jose.vcdm.52 → 0.28.1-feature.oyd.cmsm.improv.20
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/index.d.ts +5 -171
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -750
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/x509/crypto.d.ts +2 -0
- package/dist/x509/crypto.d.ts.map +1 -0
- package/dist/x509/crypto.js +28 -0
- package/dist/x509/crypto.js.map +1 -0
- package/dist/x509/index.d.ts +5 -0
- package/dist/x509/index.d.ts.map +1 -0
- package/dist/x509/index.js +21 -0
- package/dist/x509/index.js.map +1 -0
- package/dist/x509/rsa-key.d.ts +10 -0
- package/dist/x509/rsa-key.d.ts.map +1 -0
- package/dist/x509/rsa-key.js +102 -0
- package/dist/x509/rsa-key.js.map +1 -0
- package/dist/x509/rsa-signer.d.ts +24 -0
- package/dist/x509/rsa-signer.d.ts.map +1 -0
- package/dist/x509/rsa-signer.js +105 -0
- package/dist/x509/rsa-signer.js.map +1 -0
- package/dist/x509/x509-utils.d.ts +31 -0
- package/dist/x509/x509-utils.d.ts.map +1 -0
- package/dist/x509/x509-utils.js +215 -0
- package/dist/x509/x509-utils.js.map +1 -0
- package/dist/x509/x509-validator.d.ts +97 -0
- package/dist/x509/x509-validator.d.ts.map +1 -0
- package/dist/x509/x509-validator.js +489 -0
- package/dist/x509/x509-validator.js.map +1 -0
- package/package.json +12 -25
- package/src/x509/crypto.ts +5 -11
- package/src/x509/rsa-key.ts +2 -8
- package/src/x509/rsa-signer.ts +5 -9
- package/src/x509/x509-utils.ts +5 -8
- package/src/x509/x509-validator.ts +3 -6
- package/dist/index.cjs +0 -777
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -173
package/src/x509/rsa-signer.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
1
|
import * as u8a from 'uint8arrays'
|
|
3
|
-
|
|
4
|
-
import type { HashAlgorithm, KeyVisibility } from '../types'
|
|
2
|
+
import { HashAlgorithm, KeyVisibility } from '../types'
|
|
5
3
|
import { globalCrypto } from './crypto'
|
|
6
4
|
import { cryptoSubtleImportRSAKey, RSAEncryptionSchemes, RSASignatureSchemes } from './rsa-key'
|
|
7
5
|
import { PEMToJwk } from './x509-utils'
|
|
8
|
-
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
import { CryptoKey, RsaPssParams, AlgorithmIdentifier } from 'node'
|
|
6
|
+
|
|
11
7
|
export class RSASigner {
|
|
12
8
|
private readonly hashAlgorithm: HashAlgorithm
|
|
13
9
|
private readonly jwk: JsonWebKey
|
|
@@ -50,7 +46,7 @@ export class RSASigner {
|
|
|
50
46
|
|
|
51
47
|
private bufferToString(buf: ArrayBuffer) {
|
|
52
48
|
const uint8Array = new Uint8Array(buf)
|
|
53
|
-
return toString(uint8Array, 'base64url') // Needs to be base64url for JsonWebSignature2020. Don't change!
|
|
49
|
+
return u8a.toString(uint8Array, 'base64url') // Needs to be base64url for JsonWebSignature2020. Don't change!
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
public async sign(data: Uint8Array): Promise<string> {
|
|
@@ -68,7 +64,7 @@ export class RSASigner {
|
|
|
68
64
|
public async verify(data: string | Uint8Array, signature: string): Promise<boolean> {
|
|
69
65
|
const jws = signature.includes('.') ? signature.split('.')[2] : signature
|
|
70
66
|
|
|
71
|
-
const input = typeof data == 'string' ? fromString(data, 'utf-8') : data
|
|
67
|
+
const input = typeof data == 'string' ? u8a.fromString(data, 'utf-8') : data
|
|
72
68
|
|
|
73
69
|
let key = await this.getKey()
|
|
74
70
|
if (!key.usages.includes('verify')) {
|
|
@@ -78,7 +74,7 @@ export class RSASigner {
|
|
|
78
74
|
delete verifyJwk.key_ops
|
|
79
75
|
key = await cryptoSubtleImportRSAKey(verifyJwk, this.scheme, this.hashAlgorithm)
|
|
80
76
|
}
|
|
81
|
-
const verificationResult = await globalCrypto(false).subtle.verify(this.getImportParams(), key, fromString(jws, 'base64url'), input)
|
|
77
|
+
const verificationResult = await globalCrypto(false).subtle.verify(this.getImportParams(), key, u8a.fromString(jws, 'base64url'), input)
|
|
82
78
|
return verificationResult
|
|
83
79
|
}
|
|
84
80
|
}
|
package/src/x509/x509-utils.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { X509Certificate } from '@peculiar/x509'
|
|
2
2
|
import { Certificate } from 'pkijs'
|
|
3
|
-
// @ts-ignore
|
|
4
3
|
import * as u8a from 'uint8arrays'
|
|
5
|
-
const { fromString, toString } = u8a
|
|
6
4
|
// @ts-ignore
|
|
7
5
|
import keyto from '@trust/keyto'
|
|
8
|
-
import
|
|
6
|
+
import { KeyVisibility } from '../types'
|
|
9
7
|
|
|
10
|
-
import type { JsonWebKey } from '@sphereon/ssi-types'
|
|
11
8
|
// Based on (MIT licensed):
|
|
12
9
|
// https://github.com/hildjj/node-posh/blob/master/lib/index.js
|
|
13
10
|
export function pemCertChainTox5c(cert: string, maxDepth?: number): string[] {
|
|
@@ -60,7 +57,7 @@ export const pemOrDerToX509Certificate = (cert: string | Uint8Array | X509Certif
|
|
|
60
57
|
if (!DER) {
|
|
61
58
|
throw Error('Invalid cert input value supplied. PEM, DER, Bytes and X509Certificate object are supported')
|
|
62
59
|
}
|
|
63
|
-
return Certificate.fromBER(fromString(DER, 'base64pad'))
|
|
60
|
+
return Certificate.fromBER(u8a.fromString(DER, 'base64pad'))
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
export const areCertificatesEqual = (cert1: Certificate, cert2: Certificate): boolean => {
|
|
@@ -133,7 +130,7 @@ export function PEMToBinary(pem: string): Uint8Array {
|
|
|
133
130
|
.replace(/-----END [^-]+-----[^]*$/, '')
|
|
134
131
|
.replace(/\s/g, '')
|
|
135
132
|
|
|
136
|
-
return fromString(pemContents, 'base64pad')
|
|
133
|
+
return u8a.fromString(pemContents, 'base64pad')
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
/**
|
|
@@ -143,7 +140,7 @@ export function PEMToBinary(pem: string): Uint8Array {
|
|
|
143
140
|
*/
|
|
144
141
|
export const base64ToHex = (input: string, inputEncoding?: 'base64' | 'base64pad' | 'base64url' | 'base64urlpad') => {
|
|
145
142
|
const base64NoNewlines = input.replace(/[^0-9A-Za-z_\-~\/+=]*/g, '')
|
|
146
|
-
return toString(fromString(base64NoNewlines, inputEncoding ? inputEncoding : 'base64pad'), 'base16')
|
|
143
|
+
return u8a.toString(u8a.fromString(base64NoNewlines, inputEncoding ? inputEncoding : 'base64pad'), 'base16')
|
|
147
144
|
}
|
|
148
145
|
|
|
149
146
|
export const hexToBase64 = (input: number | object | string, targetEncoding?: 'base64' | 'base64pad' | 'base64url' | 'base64urlpad'): string => {
|
|
@@ -151,7 +148,7 @@ export const hexToBase64 = (input: number | object | string, targetEncoding?: 'b
|
|
|
151
148
|
if (hex.length % 2 === 1) {
|
|
152
149
|
hex = `0${hex}`
|
|
153
150
|
}
|
|
154
|
-
return toString(fromString(hex, 'base16'), targetEncoding ? targetEncoding : 'base64pad')
|
|
151
|
+
return u8a.toString(u8a.fromString(hex, 'base16'), targetEncoding ? targetEncoding : 'base64pad')
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
export const hexToPEM = (hex: string, type: KeyVisibility): string => {
|
|
@@ -6,9 +6,7 @@ import { JWK } from '@sphereon/ssi-types'
|
|
|
6
6
|
import x509 from 'js-x509-utils'
|
|
7
7
|
import { AltName, AttributeTypeAndValue, Certificate, CryptoEngine, getCrypto, id_SubjectAltName, setEngine } from 'pkijs'
|
|
8
8
|
import { container } from 'tsyringe'
|
|
9
|
-
// @ts-ignore
|
|
10
9
|
import * as u8a from 'uint8arrays'
|
|
11
|
-
const { fromString, toString } = u8a
|
|
12
10
|
import { globalCrypto } from './crypto'
|
|
13
11
|
import { areCertificatesEqual, derToPEM, pemOrDerToX509Certificate } from './x509-utils'
|
|
14
12
|
|
|
@@ -307,7 +305,6 @@ export type ParsedCertificate = {
|
|
|
307
305
|
publicKeyInfo: SubjectPublicKeyInfo
|
|
308
306
|
publicKeyJwk?: JWK
|
|
309
307
|
publicKeyRaw: Uint8Array
|
|
310
|
-
// @ts-ignore
|
|
311
308
|
publicKeyAlgorithm: Algorithm
|
|
312
309
|
certificateInfo: CertificateInfo
|
|
313
310
|
certificate: Certificate
|
|
@@ -519,10 +516,10 @@ const getDNString = (typesAndValues: AttributeTypeAndValue[]): string => {
|
|
|
519
516
|
export const getCertificateSubjectPublicKeyJWK = async (pemOrDerCert: string | Uint8Array | Certificate): Promise<JWK> => {
|
|
520
517
|
const pemOrDerStr =
|
|
521
518
|
typeof pemOrDerCert === 'string'
|
|
522
|
-
? toString(fromString(pemOrDerCert, 'base64pad'), 'base64pad')
|
|
519
|
+
? u8a.toString(u8a.fromString(pemOrDerCert, 'base64pad'), 'base64pad')
|
|
523
520
|
: pemOrDerCert instanceof Uint8Array
|
|
524
|
-
? toString(pemOrDerCert, 'base64pad')
|
|
525
|
-
: toString(fromString(pemOrDerCert.toString('base64'), 'base64pad'), 'base64pad')
|
|
521
|
+
? u8a.toString(pemOrDerCert, 'base64pad')
|
|
522
|
+
: u8a.toString(u8a.fromString(pemOrDerCert.toString('base64'), 'base64pad'), 'base64pad')
|
|
526
523
|
const pem = derToPEM(pemOrDerStr)
|
|
527
524
|
const certificate = pemOrDerToX509Certificate(pem)
|
|
528
525
|
var jwk: JWK | undefined
|