All files / src dids.ts

76.47% Statements 13/17
50% Branches 3/6
75% Functions 3/4
76.47% Lines 13/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 681x         1x 15x           1x             1x 31x   31x       31x       31x           1x 31x   31x 31x                                                      
import { InvalidDIDError } from './errors'
 
/**
* @ignore
*/
export function makeDIDFromAddress(address: string) {
  return `did:btc-addr:${address}`
}
 
/**
* @ignore
*/
export function makeDIDFromPublicKey(publicKey: string) {
  return `did:ecdsa-pub:${publicKey}`
}
 
/**
* @ignore
*/
export function getDIDType(decentralizedID: string) {
  const didParts = decentralizedID.split(':')
  
  Iif (didParts.length !== 3) {
    throw new InvalidDIDError('Decentralized IDs must have 3 parts')
  }
 
  Iif (didParts[0].toLowerCase() !== 'did') {
    throw new InvalidDIDError('Decentralized IDs must start with "did"')
  }
 
  return didParts[1].toLowerCase()
}
 
/**
* @ignore
*/
export function getAddressFromDID(decentralizedID: string) {
  const didType = getDIDType(decentralizedID)
  
  Eif (didType === 'btc-addr') {
    return decentralizedID.split(':')[2]
  } else {
    return null
  }
}
 
/*
export function getPublicKeyOrAddressFromDID(decentralizedID) {
  const didParts = decentralizedID.split(':')
 
  if (didParts.length !== 3) {
    throw new InvalidDIDError('Decentralized IDs must have 3 parts')
  }
 
  if (didParts[0].toLowerCase() !== 'did') {
    throw new InvalidDIDError('Decentralized IDs must start with "did"')
  }
 
  if (didParts[1].toLowerCase() === 'ecdsa-pub') {
    return didParts[2]
  } else if (didParts[1].toLowerCase() === 'btc-addr') {
    return didParts[2]
  } else {
    throw new InvalidDIDError('Decentralized ID format not supported')
  }
}
*/