UNPKG

did-jwt

Version:

Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients

18 lines • 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.publicKeyToAddress = publicKeyToAddress; const util_js_1 = require("../util.js"); const Digest_js_1 = require("../Digest.js"); function publicKeyToAddress(publicKey, otherAddress) { // Use the same version/prefix byte as the given address. const version = (0, util_js_1.bytesToHex)((0, util_js_1.base58ToBytes)(otherAddress).slice(0, 1)); const publicKeyBuffer = (0, util_js_1.hexToBytes)(publicKey); const publicKeyHash = (0, Digest_js_1.ripemd160)((0, Digest_js_1.sha256)(publicKeyBuffer)); const step1 = version + (0, util_js_1.bytesToHex)(publicKeyHash); const step2 = (0, Digest_js_1.sha256)((0, util_js_1.hexToBytes)(step1)); const step3 = (0, Digest_js_1.sha256)(step2); const checksum = (0, util_js_1.bytesToHex)(step3).substring(0, 8); const step4 = step1 + checksum; return (0, util_js_1.bytesToBase58)((0, util_js_1.hexToBytes)(step4)); } //# sourceMappingURL=bip122.js.map