@sphereon/ssi-sdk-ext.key-utils 0.34.1-feature.SSISDK.65.redirect.fix.260 → 0.34.1-feature.SSISDK.70.integrate.digidentity.307
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.cjs +22 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +26 -9
- package/src/types/key-util-types.ts +1 -0
package/src/functions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from '@ethersproject/random'
|
|
2
2
|
// Do not change these require statements to imports before we change to ESM. Breaks external CJS packages depending on this module
|
|
3
3
|
import { bls12_381 } from '@noble/curves/bls12-381'
|
|
4
|
-
import { ed25519 } from '@noble/curves/ed25519'
|
|
4
|
+
import { ed25519, x25519 } from '@noble/curves/ed25519'
|
|
5
5
|
import { p256 } from '@noble/curves/p256'
|
|
6
6
|
import { p384 } from '@noble/curves/p384'
|
|
7
7
|
import { p521 } from '@noble/curves/p521'
|
|
@@ -120,14 +120,20 @@ export async function importProvidedOrGeneratedKey(
|
|
|
120
120
|
// @ts-ignore
|
|
121
121
|
const type = args.options?.type ?? args.options?.key?.type ?? args.options?.keyType ?? 'Secp256r1'
|
|
122
122
|
const key = args?.options?.key
|
|
123
|
-
|
|
124
|
-
if (args.options?.x509 && key) {
|
|
123
|
+
if (key) {
|
|
125
124
|
key.meta = {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
providerName: args.providerName,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Make sure x509 options are also set on the metadata as that is what the kms will look for
|
|
129
|
+
if (args.options?.x509) {
|
|
130
|
+
key.meta = {
|
|
131
|
+
...key.meta,
|
|
132
|
+
x509: {
|
|
133
|
+
...args.options.x509,
|
|
134
|
+
...key.meta?.x509,
|
|
135
|
+
},
|
|
136
|
+
}
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
|
|
@@ -367,7 +373,7 @@ export function rsaJwkToRawHexKey(jwk: JsonWebKey): string {
|
|
|
367
373
|
// We are converting from base64 to base64url to be sure. The spec uses base64url, but in the wild we sometimes encounter a base64 string
|
|
368
374
|
const modulus = fromString(jwk.n.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), 'base64url') // 'n' is the modulus
|
|
369
375
|
const exponent = fromString(jwk.e.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), 'base64url') // 'e' is the exponent
|
|
370
|
-
|
|
376
|
+
|
|
371
377
|
return toString(modulus, 'hex') + toString(exponent, 'hex')*/
|
|
372
378
|
}
|
|
373
379
|
|
|
@@ -423,6 +429,17 @@ function octJwkToRawHexKey(jwk: JsonWebKey): string {
|
|
|
423
429
|
return toString(key, 'hex')
|
|
424
430
|
}
|
|
425
431
|
|
|
432
|
+
export function x25519PublicHexFromPrivateHex(privateKeyHex: string): string {
|
|
433
|
+
if (!/^[0-9a-fA-F]{64}$/.test(privateKeyHex)) {
|
|
434
|
+
throw new Error('Private key must be 32-byte hex (64 chars)')
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const priv = Uint8Array.from(Buffer.from(privateKeyHex, 'hex'))
|
|
438
|
+
const pub = x25519.getPublicKey(priv)
|
|
439
|
+
|
|
440
|
+
return Buffer.from(pub).toString('hex')
|
|
441
|
+
}
|
|
442
|
+
|
|
426
443
|
/**
|
|
427
444
|
* Determines the use param based upon the key/signature type or supplied use value.
|
|
428
445
|
*
|