UNPKG

@ew-did-registry/did

Version:
1 lines 3.87 kB
(()=>{"use strict";var t={920:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.Chain=e.Methods=e.DID=void 0;const o=r(622);Object.defineProperty(e,"Methods",{enumerable:!0,get:function(){return o.Methods}}),Object.defineProperty(e,"Chain",{enumerable:!0,get:function(){return o.Chain}}),e.DID=class{constructor(){this._dids=new Map}get(t){return this._dids.get(t)}set(t,e,r){return t.startsWith("did:")?this._setDid(t):void 0!==r?this._setDid(`did:${t}:${e}:${r}`):this._setDid(`did:${t}:${e}`)}_setDid(t){if(t.split(":").length>3){const[,e,r,n]=t.split(":");if(void 0===n)throw new Error("Identity cannot be undefined");if(!o.DID_SCHEME_PATTERNS.NETWORK.test(`${e}:${r}`))throw new Error("Network must not be empty and consist only of lowcase alphanumerical characters");if(void 0!==n&&!o.DID_SCHEME_PATTERNS.ID.test(n))throw new Error("Id must consist only of alphanumerical characters, dots, minuses and underscores");return this._dids.set(e,t),this}{const[,e,r]=t.split(":");if(void 0===r)throw new Error("DID must consist of three parts separated by a colon");if(!o.DID_SCHEME_PATTERNS.NETWORK.test(e))throw new Error("Network must not be empty and consist only of lowcase alphanumerical characters");if(!o.DID_SCHEME_PATTERNS.ID.test(r))throw new Error("Id must consist only of alphanumerical characters, dots, minuses and underscores");return this._dids.set(e,t),this}}},i(r(931),e),i(r(503),e)},622:(t,e)=>{var r,n;Object.defineProperty(e,"__esModule",{value:!0}),e.DID_SCHEME_PATTERNS=e.Chain=e.Methods=void 0,(n=e.Methods||(e.Methods={})).Erc725="erc725",n.Erc1056="ethr",n.Jolocom="jolo",(r=e.Chain||(e.Chain={})).EWC="ewc",r.VOLTA="volta",e.DID_SCHEME_PATTERNS={NETWORK:/^[a-z0-9]+?(:)?[a-z0-9]+?$/,ID:/^[\w.-]*(:[\w.-]*)*$/}},503:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getDIDChain=e.getDIDMethod=e.didPattern=void 0,e.didPattern="^did:[a-z0-9]+?:?[a-z0-9]+?:(0x[A-Fa-f0-9]{40})$",e.getDIDMethod=function(t){if(!t.match(e.didPattern))throw new Error("Invalid DID");const[,r]=t.split(":");return r},e.getDIDChain=function(t){if(!t.match(e.didPattern))throw new Error("Invalid DID");if(t.split(":").length>3){const[,,e]=t.split(":");return{foundChainInfo:!0,chainInfo:e}}return{foundChainInfo:!1,chainInfo:void 0}}},931:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isValidErc1056VOLTA=e.isValidErc1056EWC=e.isValidErc1056Mainnet=e.isValidErc1056=e.DIDPatternVOLTA=e.DIDPatternEWC=e.DIDPatternMainnet=e.DIDPattern=e.ethAddrPattern=void 0;const n=r(622);e.ethAddrPattern="0x[A-Fa-f0-9]{40}",e.DIDPattern=`^did:${n.Methods.Erc1056}:([A-Za-z0-9]+:)?(${e.ethAddrPattern})$`,e.DIDPatternMainnet=`^did:${n.Methods.Erc1056}:(${e.ethAddrPattern})$`,e.DIDPatternEWC=`^did:${n.Methods.Erc1056}:${n.Chain.EWC}:(${e.ethAddrPattern})$`,e.DIDPatternVOLTA=`^did:${n.Methods.Erc1056}:${n.Chain.VOLTA}:(${e.ethAddrPattern})$`,e.isValidErc1056=function(t){return new RegExp(e.DIDPattern).test(t)},e.isValidErc1056Mainnet=function(t){return new RegExp(e.DIDPatternMainnet).test(t)},e.isValidErc1056EWC=function(t){return new RegExp(e.DIDPatternEWC).test(t)},e.isValidErc1056VOLTA=function(t){return new RegExp(e.DIDPatternVOLTA).test(t)}}},e={},r=function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(920),n=exports;for(var i in r)n[i]=r[i];r.__esModule&&Object.defineProperty(n,"__esModule",{value:!0})})();