UNPKG

@stacks/auth

Version:

Authentication for Stacks apps.

37 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAddressFromDID = exports.getDIDType = exports.makeDIDFromPublicKey = exports.makeDIDFromAddress = void 0; const common_1 = require("@stacks/common"); function makeDIDFromAddress(address) { return `did:btc-addr:${address}`; } exports.makeDIDFromAddress = makeDIDFromAddress; function makeDIDFromPublicKey(publicKey) { return `did:ecdsa-pub:${publicKey}`; } exports.makeDIDFromPublicKey = makeDIDFromPublicKey; function getDIDType(decentralizedID) { const didParts = decentralizedID.split(':'); if (didParts.length !== 3) { throw new common_1.InvalidDIDError('Decentralized IDs must have 3 parts'); } if (didParts[0].toLowerCase() !== 'did') { throw new common_1.InvalidDIDError('Decentralized IDs must start with "did"'); } return didParts[1].toLowerCase(); } exports.getDIDType = getDIDType; function getAddressFromDID(decentralizedID) { if (decentralizedID) { const didType = getDIDType(decentralizedID); if (didType === 'btc-addr') { return decentralizedID.split(':')[2]; } else { return undefined; } } return undefined; } exports.getAddressFromDID = getAddressFromDID; //# sourceMappingURL=dids.js.map