@sphereon/ssi-sdk-ext.did-utils
Advanced tools
Comparing version 0.13.1-next.10 to 0.13.1-next.11
@@ -55,2 +55,3 @@ "use strict"; | ||
const u8a = __importStar(require("uint8arrays")); | ||
const transactions_1 = require("@ethersproject/transactions"); | ||
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils"); | ||
@@ -172,5 +173,2 @@ const getFirstKeyWithRelation = (identifier, context, vmRelationship, errorOnNotFound) => __awaiter(void 0, void 0, void 0, function* () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const rsaDidWeb = identifier.keys && identifier.keys.length > 0 && identifier.keys.find((key) => key.type === 'RSA') && didDocument; | ||
// We skip mapping in case the identifier is RSA and a did document is supplied. | ||
const keys = rsaDidWeb ? [] : yield (0, utils_1.mapIdentifierKeysToDoc)(identifier, section, context); | ||
const didDoc = didDocument !== null && didDocument !== void 0 ? didDocument : (yield getAgentResolver(context) | ||
@@ -182,5 +180,8 @@ .resolve(identifier.did) | ||
} | ||
// const rsaDidWeb = identifier.keys && identifier.keys.length > 0 && identifier.keys.find((key) => key.type === 'RSA') && didDocument | ||
// We skip mapping in case the identifier is RSA and a did document is supplied. | ||
const keys = didDoc ? [] : yield (0, utils_1.mapIdentifierKeysToDoc)(identifier, section, context); | ||
// dereference all key agreement keys from DID document and normalize | ||
const documentKeys = yield dereferenceDidKeysWithJwkSupport(didDoc, section, context); | ||
const localKeys = identifier.keys.filter(utils_1.isDefined); | ||
const localKeys = section === 'keyAgreement' ? (0, utils_1.convertIdentifierEncryptionKeys)(identifier) : (0, utils_1.compressIdentifierSecp256k1Keys)(identifier); | ||
// finally map the didDocument keys to the identifier keys by comparing `publicKeyHex` | ||
@@ -190,5 +191,10 @@ const extendedKeys = documentKeys | ||
/*if (verificationMethod.type !== 'JsonWebKey2020') { | ||
return null | ||
}*/ | ||
const localKey = localKeys.find((localKey) => { var _a; return localKey.publicKeyHex === verificationMethod.publicKeyHex || ((_a = verificationMethod.publicKeyHex) === null || _a === void 0 ? void 0 : _a.startsWith(localKey.publicKeyHex)); }); | ||
return null | ||
}*/ | ||
const localKey = localKeys.find((localKey) => { | ||
var _a; | ||
return localKey.publicKeyHex === verificationMethod.publicKeyHex || | ||
((_a = verificationMethod.publicKeyHex) === null || _a === void 0 ? void 0 : _a.startsWith(localKey.publicKeyHex)) || | ||
compareBlockchainAccountId(localKey, verificationMethod); | ||
}); | ||
if (localKey) { | ||
@@ -207,2 +213,27 @@ const { meta } = localKey, localProps = __rest(localKey, ["meta"]); | ||
exports.mapIdentifierKeysToDocWithJwkSupport = mapIdentifierKeysToDocWithJwkSupport; | ||
/** | ||
* Compares the `blockchainAccountId` of a `EcdsaSecp256k1RecoveryMethod2020` verification method with the address | ||
* computed from a locally managed key. | ||
* | ||
* @returns true if the local key address corresponds to the `blockchainAccountId` | ||
* | ||
* @param localKey - The locally managed key | ||
* @param verificationMethod - a {@link did-resolver#VerificationMethod | VerificationMethod} with a | ||
* `blockchainAccountId` | ||
* | ||
* @beta This API may change without a BREAKING CHANGE notice. | ||
*/ | ||
function compareBlockchainAccountId(localKey, verificationMethod) { | ||
var _a, _b; | ||
if ((verificationMethod.type !== 'EcdsaSecp256k1RecoveryMethod2020' && verificationMethod.type !== 'EcdsaSecp256k1VerificationKey2019') || | ||
localKey.type !== 'Secp256k1') { | ||
return false; | ||
} | ||
let vmEthAddr = (0, utils_1.getEthereumAddress)(verificationMethod); | ||
if ((_a = localKey.meta) === null || _a === void 0 ? void 0 : _a.account) { | ||
return vmEthAddr === ((_b = localKey.meta) === null || _b === void 0 ? void 0 : _b.account.toLowerCase()); | ||
} | ||
const computedAddr = (0, transactions_1.computeAddress)('0x' + localKey.publicKeyHex).toLowerCase(); | ||
return computedAddr === vmEthAddr; | ||
} | ||
function getAgentDIDMethods(context) { | ||
@@ -209,0 +240,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@sphereon/ssi-sdk-ext.did-utils", | ||
"description": "DID Utils", | ||
"version": "0.13.1-next.10+a555f11", | ||
"version": "0.13.1-next.11+b5b7f76", | ||
"source": "src/index.ts", | ||
@@ -13,4 +13,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@ethersproject/transactions": "^5.7.0", | ||
"@sphereon/did-uni-client": "^0.6.0", | ||
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.10+a555f11", | ||
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.11+b5b7f76", | ||
"@veramo/core": "4.2.0", | ||
@@ -38,3 +39,3 @@ "@veramo/utils": "4.2.0", | ||
"keywords": [], | ||
"gitHead": "a555f115901f325fbee26be5aeda23f808b48a1d" | ||
"gitHead": "b5b7f76496e328e264aa38f351f5a64c4ca03dba" | ||
} |
@@ -7,3 +7,6 @@ import { UniResolver } from '@sphereon/did-uni-client' | ||
_NormalizedVerificationMethod, | ||
compressIdentifierSecp256k1Keys, | ||
convertIdentifierEncryptionKeys, | ||
extractPublicKeyHex, | ||
getEthereumAddress, | ||
isDefined, | ||
@@ -17,2 +20,3 @@ mapIdentifierKeysToDoc, | ||
import { IDIDOptions, IIdentifierOpts } from './types' | ||
import { computeAddress } from '@ethersproject/transactions' | ||
import { ENC_KEY_ALGS, hexKeyFromPEMBasedJwk, JwkKeyUse, toJwk } from '@sphereon/ssi-sdk-ext.key-utils' | ||
@@ -148,6 +152,2 @@ | ||
): Promise<_ExtendedIKey[]> { | ||
const rsaDidWeb = identifier.keys && identifier.keys.length > 0 && identifier.keys.find((key) => key.type === 'RSA') && didDocument | ||
// We skip mapping in case the identifier is RSA and a did document is supplied. | ||
const keys = rsaDidWeb ? [] : await mapIdentifierKeysToDoc(identifier, section, context) | ||
const didDoc = | ||
@@ -161,6 +161,13 @@ didDocument ?? | ||
} | ||
// const rsaDidWeb = identifier.keys && identifier.keys.length > 0 && identifier.keys.find((key) => key.type === 'RSA') && didDocument | ||
// We skip mapping in case the identifier is RSA and a did document is supplied. | ||
const keys = didDoc ? [] : await mapIdentifierKeysToDoc(identifier, section, context) | ||
// dereference all key agreement keys from DID document and normalize | ||
const documentKeys: VerificationMethod[] = await dereferenceDidKeysWithJwkSupport(didDoc, section, context) | ||
const localKeys = identifier.keys.filter(isDefined) | ||
const localKeys = section === 'keyAgreement' ? convertIdentifierEncryptionKeys(identifier) : compressIdentifierSecp256k1Keys(identifier) | ||
// finally map the didDocument keys to the identifier keys by comparing `publicKeyHex` | ||
@@ -170,6 +177,9 @@ const extendedKeys: _ExtendedIKey[] = documentKeys | ||
/*if (verificationMethod.type !== 'JsonWebKey2020') { | ||
return null | ||
}*/ | ||
return null | ||
}*/ | ||
const localKey = localKeys.find( | ||
(localKey) => localKey.publicKeyHex === verificationMethod.publicKeyHex || verificationMethod.publicKeyHex?.startsWith(localKey.publicKeyHex) | ||
(localKey) => | ||
localKey.publicKeyHex === verificationMethod.publicKeyHex || | ||
verificationMethod.publicKeyHex?.startsWith(localKey.publicKeyHex) || | ||
compareBlockchainAccountId(localKey, verificationMethod) | ||
) | ||
@@ -188,2 +198,29 @@ if (localKey) { | ||
/** | ||
* Compares the `blockchainAccountId` of a `EcdsaSecp256k1RecoveryMethod2020` verification method with the address | ||
* computed from a locally managed key. | ||
* | ||
* @returns true if the local key address corresponds to the `blockchainAccountId` | ||
* | ||
* @param localKey - The locally managed key | ||
* @param verificationMethod - a {@link did-resolver#VerificationMethod | VerificationMethod} with a | ||
* `blockchainAccountId` | ||
* | ||
* @beta This API may change without a BREAKING CHANGE notice. | ||
*/ | ||
function compareBlockchainAccountId(localKey: IKey, verificationMethod: VerificationMethod): boolean { | ||
if ( | ||
(verificationMethod.type !== 'EcdsaSecp256k1RecoveryMethod2020' && verificationMethod.type !== 'EcdsaSecp256k1VerificationKey2019') || | ||
localKey.type !== 'Secp256k1' | ||
) { | ||
return false | ||
} | ||
let vmEthAddr = getEthereumAddress(verificationMethod) | ||
if (localKey.meta?.account) { | ||
return vmEthAddr === localKey.meta?.account.toLowerCase() | ||
} | ||
const computedAddr = computeAddress('0x' + localKey.publicKeyHex).toLowerCase() | ||
return computedAddr === vmEthAddr | ||
} | ||
export async function getAgentDIDMethods(context: IAgentContext<IDIDManager>) { | ||
@@ -190,0 +227,0 @@ return (await context.agent.didManagerGetProviders()).map((provider) => provider.toLowerCase().replace('did:', '')) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
76691
1019
9