Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ew-did-registry/did

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ew-did-registry/did - npm Package Compare versions

Comparing version 0.6.3-alpha.458.0 to 0.6.3-alpha.479.0

dist/index.esm.js

111

dist/index.js

@@ -1,110 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Chain = exports.Methods = exports.DID = void 0;
const models_1 = require("./models");
Object.defineProperty(exports, "Methods", { enumerable: true, get: function () { return models_1.Methods; } });
Object.defineProperty(exports, "Chain", { enumerable: true, get: function () { return models_1.Chain; } });
/* eslint-disable no-underscore-dangle */
class DID {
constructor() {
/**
* Mappings from methods to DIDs
*/
this._dids = new Map();
}
/**
* Gets a DID for a particular method
*
* @example
* ```typescript
* import { DID, Network } from '@ew-did-registry/did';
*
* const did = new DID();
* did.set('bitcoin', 'method_specific_id');
* console.log(did.get('bitcoin')); // 'did:bitcoin:method_specific_id'
*
* const did = new DID();
* did.set(Methods.Erc1056, 'method_specific_id');
* console.log(did.get(Methods.Erc1056)); // 'did:eth:method_specific_id'
* ```
*
* @param { Methods } method
*
* @returns { string|undefined }
*/
get(method) {
return this._dids.get(method);
}
/**
* Sets a DID for the provided method
*
* @example
* ```typescript
* import { DID } from '@ew-did-registry/did';
*
* const did = new DID();
* did.set('eth', 'method_specific_id');
* console.log(did.get('eth')); // 'did:eth:method_specific_id'
* ```
*
* @param { Methods } method
* @param {string} chain
* @param {string} id
*
* @returns {void}
*/
// eslint-disable-next-line no-dupe-class-members
set(method, chain, id) {
if (method.startsWith('did:')) {
return this._setDid(method);
}
if (id !== undefined) {
return this._setDid(`did:${method}:${chain}:${id}`);
}
return this._setDid(`did:${method}:${chain}`);
}
_setDid(did) {
if (did.split(':').length > 3) {
const [, method, chain, id] = did.split(':');
if (id === undefined) {
throw new Error('Identity cannot be undefined');
}
if (!models_1.DID_SCHEME_PATTERNS.NETWORK.test(`${method}:${chain}`)) {
throw new Error('Network must not be empty and consist only of lowcase alphanumerical characters');
}
if (id !== undefined && !models_1.DID_SCHEME_PATTERNS.ID.test(id)) {
throw new Error('Id must consist only of alphanumerical characters, dots, minuses and underscores');
}
this._dids.set(method, did);
return this;
}
else {
const [, method, id] = did.split(':');
if (id === undefined) {
throw new Error('DID must consist of three parts separated by a colon');
}
if (!models_1.DID_SCHEME_PATTERNS.NETWORK.test(method)) {
throw new Error('Network must not be empty and consist only of lowcase alphanumerical characters');
}
if (!models_1.DID_SCHEME_PATTERNS.ID.test(id)) {
throw new Error('Id must consist only of alphanumerical characters, dots, minuses and underscores');
}
this._dids.set(method, did);
return this;
}
}
}
exports.DID = DID;
__exportStar(require("./utils/validation"), exports);
__exportStar(require("./utils/parser"), exports);
//# sourceMappingURL=index.js.map
(()=>{"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),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}: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.isValidErc1056=e.DIDPatternVOLTA=e.DIDPatternEWC=e.DIDPattern=e.ethAddrPattern=void 0;const n=r(622);e.ethAddrPattern="0x[A-Fa-f0-9]{40}",e.DIDPattern=`^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.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})})();
{
"name": "@ew-did-registry/did",
"version": "0.6.3-alpha.458.0",
"version": "0.6.3-alpha.479.0",
"publishConfig": {

@@ -10,6 +10,7 @@ "access": "public",

"main": "./dist/index.js",
"browser": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"scripts": {
"test": "../../node_modules/.bin/mocha -r ts-node/register test/**/*.test.ts",
"compile": "../../node_modules/.bin/tsc",
"test": "mocha -r ts-node/register test/**/*.test.ts",
"compile": "webpack --config ../../webpack.config.js",
"lint": "../../node_modules/.bin/eslint src/**/*.ts",

@@ -30,3 +31,8 @@ "fix": "../../node_modules/.bin/eslint src/**/*.ts --fix"

"devDependencies": {
"@ew-did-registry/keys": "0.6.3-alpha.458.0"
"@ew-did-registry/keys": "0.6.3-alpha.479.0",
"node-polyfill-webpack-plugin": "^1.1.4",
"ts-loader": "^9.2.6",
"webpack": "^5.68.0",
"webpack-cli": "^4.9.2",
"webpack-merge": "^5.8.0"
},

@@ -41,3 +47,3 @@ "homepage": "https://github.com/energywebfoundation/ew-did-registry/#readme",

},
"gitHead": "6ce1c726cd22bc6482c527f2ffeb96a1f8019e77"
"gitHead": "6799fe007c1dc9a1e0b43f973fb516938e545673"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc