Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@veramo/utils

Package Overview
Dependencies
Maintainers
3
Versions
375
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veramo/utils - npm Package Compare versions

Comparing version 5.6.1-next.34 to 5.6.1-next.35

9

build/did-utils.d.ts

@@ -24,3 +24,3 @@ import { DIDDocumentSection, IAgentContext, IIdentifier, IKey, IResolver } from '@veramo/core-types';

*
* @returns the array of converted keys filtered to contain only those usable for encryption.
* @returns the array of converted keys filtered to contain ONLY X25519 keys usable for encryption.
*

@@ -109,7 +109,10 @@ * @beta This API may change without a BREAKING CHANGE notice.

* @param convert - when this flag is set to true, Ed25519 keys are converted to their X25519 pairs
* @returns the hex encoding of the public key
* @returns the hex encoding of the public key along with the inferred key type
*
* @beta This API may change without a BREAKING CHANGE notice.
*/
export declare function extractPublicKeyHex(pk: _ExtendedVerificationMethod, convert?: boolean): string;
export declare function extractPublicKeyHex(pk: _ExtendedVerificationMethod, convert?: boolean): {
publicKeyHex: string;
keyType: string | undefined;
};
//# sourceMappingURL=did-utils.d.ts.map

@@ -38,3 +38,3 @@ import { SigningKey, computeAddress } from 'ethers';

*
* @returns the array of converted keys filtered to contain only those usable for encryption.
* @returns the array of converted keys filtered to contain ONLY X25519 keys usable for encryption.
*

@@ -101,13 +101,9 @@ * @beta This API may change without a BREAKING CHANGE notice.

function compareBlockchainAccountId(localKey, verificationMethod) {
if (!(verificationMethod.type === 'EcdsaSecp256k1RecoveryMethod2020' ||
verificationMethod.type === 'EcdsaSecp256k1VerificationKey2019' ||
(verificationMethod.type === 'JsonWebKey2020' &&
verificationMethod.publicKeyJwk &&
verificationMethod.publicKeyJwk.crv === 'secp256k1') ||
localKey.type === 'Secp256k1')) {
if (localKey.type !== 'Secp256k1') {
return false;
}
let vmEthAddr = getEthereumAddress(verificationMethod);
const localAccount = localKey.meta?.account ?? localKey.meta?.ethereumAddress;
if (localKey.meta?.account) {
return vmEthAddr === localKey.meta?.account.toLowerCase();
return vmEthAddr === localAccount.toLowerCase();
}

@@ -136,8 +132,8 @@ const computedAddr = computeAddress('0x' + localKey.publicKeyHex).toLowerCase();

}
else if (verificationMethod.publicKeyHex ||
verificationMethod.publicKeyBase58 ||
verificationMethod.publicKeyBase64 ||
verificationMethod.publicKeyJwk) {
const pbBytes = extractPublicKeyBytes(verificationMethod);
const pbHex = SigningKey.computePublicKey(pbBytes, false);
else {
const { keyBytes, keyType } = extractPublicKeyBytes(verificationMethod);
if (keyType !== 'Secp256k1') {
return undefined;
}
const pbHex = SigningKey.computePublicKey(keyBytes, false);
vmEthAddr = computeAddress(pbHex).toLowerCase();

@@ -267,3 +263,3 @@ }

.map((key) => {
const hexKey = extractPublicKeyHex(key, convert);
const { publicKeyHex: hexKey, keyType } = extractPublicKeyHex(key, convert);
const { publicKeyHex, publicKeyBase58, publicKeyMultibase, publicKeyBase64, publicKeyJwk, ...keyProps } = key;

@@ -273,8 +269,10 @@ const newKey = { ...keyProps, publicKeyHex: hexKey };

// Should type of `newKey` change?
if (convert && 'Ed25519VerificationKey2018' === newKey.type) {
newKey.type = 'X25519KeyAgreementKey2019';
if (convert) {
if ('Ed25519VerificationKey2018' === newKey.type) {
newKey.type = 'X25519KeyAgreementKey2019';
}
else if ('Ed25519VerificationKey2020' === newKey.type || 'X25519' === keyType) {
newKey.type = 'X25519KeyAgreementKey2020';
}
}
else if (convert && ['Ed25519VerificationKey2020', 'JsonWebKey2020'].includes(newKey.type)) {
newKey.type = 'X25519KeyAgreementKey2020';
}
return newKey;

@@ -288,3 +286,3 @@ });

* @param convert - when this flag is set to true, Ed25519 keys are converted to their X25519 pairs
* @returns the hex encoding of the public key
* @returns the hex encoding of the public key along with the inferred key type
*

@@ -294,15 +292,11 @@ * @beta This API may change without a BREAKING CHANGE notice.

export function extractPublicKeyHex(pk, convert = false) {
let keyBytes = extractPublicKeyBytes(pk);
let { keyBytes, keyType } = extractPublicKeyBytes(pk);
if (convert) {
if (['Ed25519', 'Ed25519VerificationKey2018', 'Ed25519VerificationKey2020'].includes(pk.type) ||
(pk.type === 'JsonWebKey2020' && pk.publicKeyJwk?.crv === 'Ed25519')) {
if (keyType === 'Ed25519') {
keyBytes = convertEd25519PublicKeyToX25519(keyBytes);
keyType = 'X25519';
}
else if (!['X25519', 'X25519KeyAgreementKey2019', 'X25519KeyAgreementKey2020'].includes(pk.type) &&
!(pk.type === 'JsonWebKey2020' && pk.publicKeyJwk?.crv === 'X25519')) {
return '';
}
}
return bytesToHex(keyBytes);
return { publicKeyHex: bytesToHex(keyBytes), keyType };
}
//# sourceMappingURL=did-utils.js.map

@@ -96,4 +96,5 @@ import { SupportedKeyTypes } from './types/utility-types.js';

export function generateJwkFromVerificationMethod(keyType, key, keyUse) {
return createJWK(keyType, extractPublicKeyHex(key), keyUse);
const { publicKeyHex, keyType: extractedType } = extractPublicKeyHex(key);
return createJWK(keyType, publicKeyHex, keyUse);
}
//# sourceMappingURL=jwk-did-utils.js.map
{
"name": "@veramo/utils",
"description": "Helper methods for Veramo plugins",
"version": "5.6.1-next.34+ade95c70a",
"version": "5.6.1-next.35+165de3549",
"main": "build/index.js",

@@ -15,8 +15,8 @@ "exports": "./build/index.js",

"@noble/curves": "^1.1.0",
"@veramo/core-types": "^5.6.1-next.34+ade95c70a",
"@veramo/core-types": "^5.6.1-next.35+165de3549",
"credential-status": "^2.0.5",
"cross-fetch": "^4.0.0",
"debug": "^4.3.3",
"did-jwt": "^7.4.1",
"did-jwt-vc": "^3.2.10",
"did-jwt": "^8.0.0",
"did-jwt-vc": "^4.0.0",
"did-resolver": "^4.1.0",

@@ -66,3 +66,3 @@ "ethers": "^6.9.0",

],
"gitHead": "ade95c70a0bd4fb32b36bb27e8e955a3c6198369"
"gitHead": "165de3549ccfd3d7c84514608ac3ea9e56a7b807"
}

@@ -78,7 +78,7 @@ import { extractPublicKeyHex, getChainIdForDidEthr, getEthereumAddress } from '../did-utils.js'

// // multibase + multicodec
let expectedMultibase = `z6MkmhgpMDfiVVfLShamhYVCsWX6jQLVmwxXLtUykKFw3LwJ`;
let expectedMultibase = `z6MkmhgpMDfiVVfLShamhYVCsWX6jQLVmwxXLtUykKFw3LwJ`
expect(computedMultibase).toEqual(expectedMultibase)
const computedHex = extractPublicKeyHex({
const computed = extractPublicKeyHex({
publicKeyMultibase: expectedMultibase,

@@ -90,3 +90,3 @@ type: 'Ed25519VerificationKey2020',

expect(computedHex).toEqual(publicKeyHex)
expect(computed).toEqual({ publicKeyHex, keyType: 'Ed25519' })
})

@@ -99,3 +99,3 @@

// // multibase + multicodec
let expectedMultibase = `z6MkmhgpMDfiVVfLShamhYVCsWX6jQLVmwxXLtUykKFw3LwJ`;
let expectedMultibase = `z6MkmhgpMDfiVVfLShamhYVCsWX6jQLVmwxXLtUykKFw3LwJ`

@@ -105,7 +105,7 @@ expect(computedMultibase).toEqual(expectedMultibase)

const computedXMultibase = bytesToMultibase(hexToBytes(publicKeyHex), 'base58btc', 'x25519-pub')
let expectedXMultibase = `z6LSivbwHHE9FQtcRb7qYd3KM1Bakybm4ftKXrHjQVwSqVvg`;
let expectedXMultibase = `z6LSivbwHHE9FQtcRb7qYd3KM1Bakybm4ftKXrHjQVwSqVvg`
expect(computedXMultibase).toEqual(expectedXMultibase)
const computedHex = extractPublicKeyHex({
const computed = extractPublicKeyHex({
publicKeyMultibase: expectedMultibase,

@@ -117,4 +117,4 @@ type: 'Ed25519VerificationKey2020',

expect(computedHex).toEqual(publicKeyHex)
expect(computed).toEqual({ publicKeyHex, keyType: 'Ed25519' })
})
})

@@ -49,3 +49,3 @@ import { SigningKey, computeAddress } from 'ethers'

*
* @returns the array of converted keys filtered to contain only those usable for encryption.
* @returns the array of converted keys filtered to contain ONLY X25519 keys usable for encryption.
*

@@ -113,17 +113,9 @@ * @beta This API may change without a BREAKING CHANGE notice.

function compareBlockchainAccountId(localKey: IKey, verificationMethod: VerificationMethod): boolean {
if (
!(
verificationMethod.type === 'EcdsaSecp256k1RecoveryMethod2020' ||
verificationMethod.type === 'EcdsaSecp256k1VerificationKey2019' ||
(verificationMethod.type === 'JsonWebKey2020' &&
verificationMethod.publicKeyJwk &&
verificationMethod.publicKeyJwk.crv === 'secp256k1') ||
localKey.type === 'Secp256k1'
)
) {
if (localKey.type !== 'Secp256k1') {
return false
}
let vmEthAddr = getEthereumAddress(verificationMethod)
const localAccount = localKey.meta?.account ?? localKey.meta?.ethereumAddress
if (localKey.meta?.account) {
return vmEthAddr === localKey.meta?.account.toLowerCase()
return vmEthAddr === localAccount.toLowerCase()
}

@@ -151,10 +143,8 @@ const computedAddr = computeAddress('0x' + localKey.publicKeyHex).toLowerCase()

vmEthAddr = verificationMethod.blockchainAccountId.split(':')[2]?.toLowerCase()
} else if (
verificationMethod.publicKeyHex ||
verificationMethod.publicKeyBase58 ||
verificationMethod.publicKeyBase64 ||
verificationMethod.publicKeyJwk
) {
const pbBytes = extractPublicKeyBytes(verificationMethod)
const pbHex = SigningKey.computePublicKey(pbBytes, false)
} else {
const { keyBytes, keyType } = extractPublicKeyBytes(verificationMethod)
if (keyType !== 'Secp256k1') {
return undefined
}
const pbHex = SigningKey.computePublicKey(keyBytes, false)

@@ -308,3 +298,3 @@ vmEthAddr = computeAddress(pbHex).toLowerCase()

.map((key) => {
const hexKey = extractPublicKeyHex(key, convert)
const { publicKeyHex: hexKey, keyType } = extractPublicKeyHex(key, convert)
const {

@@ -322,6 +312,8 @@ publicKeyHex,

// Should type of `newKey` change?
if (convert && 'Ed25519VerificationKey2018' === newKey.type) {
newKey.type = 'X25519KeyAgreementKey2019'
} else if (convert && ['Ed25519VerificationKey2020', 'JsonWebKey2020'].includes(newKey.type)) {
newKey.type = 'X25519KeyAgreementKey2020'
if (convert) {
if ('Ed25519VerificationKey2018' === newKey.type) {
newKey.type = 'X25519KeyAgreementKey2019'
} else if ('Ed25519VerificationKey2020' === newKey.type || 'X25519' === keyType) {
newKey.type = 'X25519KeyAgreementKey2020'
}
}

@@ -338,22 +330,21 @@

* @param convert - when this flag is set to true, Ed25519 keys are converted to their X25519 pairs
* @returns the hex encoding of the public key
* @returns the hex encoding of the public key along with the inferred key type
*
* @beta This API may change without a BREAKING CHANGE notice.
*/
export function extractPublicKeyHex(pk: _ExtendedVerificationMethod, convert: boolean = false): string {
let keyBytes = extractPublicKeyBytes(pk)
export function extractPublicKeyHex(
pk: _ExtendedVerificationMethod,
convert: boolean = false,
): {
publicKeyHex: string
keyType: string | undefined
} {
let { keyBytes, keyType } = extractPublicKeyBytes(pk)
if (convert) {
if (
['Ed25519', 'Ed25519VerificationKey2018', 'Ed25519VerificationKey2020'].includes(pk.type) ||
(pk.type === 'JsonWebKey2020' && pk.publicKeyJwk?.crv === 'Ed25519')
) {
if (keyType === 'Ed25519') {
keyBytes = convertEd25519PublicKeyToX25519(keyBytes)
} else if (
!['X25519', 'X25519KeyAgreementKey2019', 'X25519KeyAgreementKey2020'].includes(pk.type) &&
!(pk.type === 'JsonWebKey2020' && pk.publicKeyJwk?.crv === 'X25519')
) {
return ''
keyType = 'X25519'
}
}
return bytesToHex(keyBytes)
return { publicKeyHex: bytesToHex(keyBytes), keyType }
}

@@ -112,3 +112,4 @@ import { JwkDidSupportedKeyTypes, KeyUse, SupportedKeyTypes } from './types/utility-types.js'

) {
return createJWK(keyType, extractPublicKeyHex(key), keyUse)
const { publicKeyHex, keyType: extractedType } = extractPublicKeyHex(key)
return createJWK(keyType, publicKeyHex, keyUse)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc