jsonld-signatures-merkleproof2019
Version:
A jsonld signature implementation to support MerkleProof2019 verification in Verifiable Credential context
45 lines (44 loc) • 2.47 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { publicKeyUInt8ArrayFromJwk, publicKeyUInt8ArrayFromMultibase } from '../utils/keyUtils';
import { computeBitcoinAddressFromPublicKey, computeEthereumAddressFromPublicKey } from '../utils/issuingAddress';
import getText from '../helpers/getText';
import VerifierError from '../models/VerifierError';
import { SupportedChains } from '@blockcerts/explorer-lookup';
export default function deriveIssuingAddressFromPublicKey(verificationMethodPublicKey, chain) {
return __awaiter(this, void 0, void 0, function* () {
let publicKey;
if ('publicKeyJwk' in verificationMethodPublicKey) {
publicKey = publicKeyUInt8ArrayFromJwk(verificationMethodPublicKey.publicKeyJwk);
}
else if ('publicKeyMultibase' in verificationMethodPublicKey) {
publicKey = yield publicKeyUInt8ArrayFromMultibase(verificationMethodPublicKey);
}
const baseError = getText('errors', 'identityErrorBaseMessage');
let address = '';
switch (chain.code) {
case SupportedChains.Bitcoin:
case SupportedChains.Mocknet:
case SupportedChains.Testnet:
address = computeBitcoinAddressFromPublicKey(publicKey, chain);
break;
case SupportedChains.Ethmain:
case SupportedChains.Ethropst:
case SupportedChains.Ethrinkeby:
case SupportedChains.Ethgoerli:
case SupportedChains.Ethsepolia:
address = computeEthereumAddressFromPublicKey(publicKey, chain);
break;
default:
throw new VerifierError('deriveIssuingAddressFromPublicKey', `${baseError} - ${getText('errors', 'deriveIssuingAddressFromPublicKey')}`);
}
return address;
});
}