@sphereon/ssi-sdk-ext.key-utils 0.34.1-feature.SSISDK.78.280 → 0.34.1-feature.SSISDK.82.and.SSISDK.70.345

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/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'
@@ -122,6 +122,7 @@ export async function importProvidedOrGeneratedKey(
122
122
  const key = args?.options?.key
123
123
  if (key) {
124
124
  key.meta = {
125
+ ...key.meta,
125
126
  providerName: args.providerName,
126
127
  }
127
128
 
@@ -164,7 +165,7 @@ export async function importProvidedOrGeneratedKey(
164
165
  meta: {
165
166
  ...key?.meta,
166
167
  algorithms: keyMetaAlgorithmsFromKeyType(type),
167
- keyAlias: args.alias,
168
+ ...(key?.meta?.keyAlias ? {} : { keyAlias: args.alias }),
168
169
  },
169
170
  })
170
171
  }
@@ -373,7 +374,7 @@ export function rsaJwkToRawHexKey(jwk: JsonWebKey): string {
373
374
  // We are converting from base64 to base64url to be sure. The spec uses base64url, but in the wild we sometimes encounter a base64 string
374
375
  const modulus = fromString(jwk.n.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), 'base64url') // 'n' is the modulus
375
376
  const exponent = fromString(jwk.e.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''), 'base64url') // 'e' is the exponent
376
-
377
+
377
378
  return toString(modulus, 'hex') + toString(exponent, 'hex')*/
378
379
  }
379
380
 
@@ -429,6 +430,17 @@ function octJwkToRawHexKey(jwk: JsonWebKey): string {
429
430
  return toString(key, 'hex')
430
431
  }
431
432
 
433
+ export function x25519PublicHexFromPrivateHex(privateKeyHex: string): string {
434
+ if (!/^[0-9a-fA-F]{64}$/.test(privateKeyHex)) {
435
+ throw new Error('Private key must be 32-byte hex (64 chars)')
436
+ }
437
+
438
+ const priv = Uint8Array.from(Buffer.from(privateKeyHex, 'hex'))
439
+ const pub = x25519.getPublicKey(priv)
440
+
441
+ return Buffer.from(pub).toString('hex')
442
+ }
443
+
432
444
  /**
433
445
  * Determines the use param based upon the key/signature type or supplied use value.
434
446
  *