module import { Did , PublicKeyPem , PublicKeyMeta } from '../../types' ; const DID_URL_REGEX = /^did:(?<method>[a-z0-9]+):(?<idstring>[A-Za-z0-9\.\-_]+)(?:#(?<fragment>.*))?$/ ; const IDSTRING_REGEX = /^(?<channelRoot>[A-Z9]{81})_?$/ ; function param { object } channelRoot returns { string } link export const encodeToDid = ( channelRoot ) : Did => { const did = `did:tangle:${ channelRoot }_` ; return did ; } ; function param { string } tangleid - TangleID which follow the DID scheme
 *    https .
 *  returns { { method : string , idstring : string , fragment : string , channelRoot : string } } export const decodeFromDid = ( tangleid ) => { const decoded = decodeFromDidUrl ( tangleid ) ; if ( decoded . method !== 'tangle' ) { throw new TypeError ( `Unsupport method '${ decoded . method }'` ) ; } const matches = IDSTRING_REGEX . exec ( decoded . idstring ) ; if ( matches === null ) { throw new Error ( 'Invalid idstring' ) ; } const [ , channelRoot ] = matches ; return { ... decoded , channelRoot } ; } ; function param { string } url return { boolean } export const isDidUrl = ( url ) : boolean => { return DID_URL_REGEX . test ( url ) ; } ; function param { string } url return { { did : string , method : string , idstring : string , fragment : string | null } } *   The information of the DID URL.  https export const decodeFromDidUrl = ( url ) => { const matches = DID_URL_REGEX . exec ( url ) ; if ( matches === null ) { throw new Error ( 'Invalid DID URL' ) ; } const [ , method , idstring , fragment ] = matches ; return { did : `did:${ method }:${ idstring }` , method , idstring , fragment : fragment || null } ; } ; function param { string } controller param { string [ ] } publicKeyPems returns { Object [ ] } export const createMetaPublicKeys = ( controller , publicKeyPems ) : PublicKeyMeta [ ] => { if ( controller === undefined ) { throw new Error ( 'controller is not specified' ) ; } if ( publicKeyPems === undefined ) { throw new Error ( 'publicKeyPems is not specified' ) ; } return publicKeyPems . map ( ( publicKeyPem , index ) => ( { id : `${ controller }#keys-${ index + 1 }` , type : 'RsaVerificationKey2018' , controller , publicKeyPem } ) ) ; } ;