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.403.0 to 0.6.3-alpha.426.0

2

dist/index.d.ts

@@ -48,4 +48,4 @@ import { IDID } from './interface';

}
export { IDID, DID, Methods, Chain, };
export { IDID, DID, Methods, Chain };
export * from './utils/validation';
export * from './utils/parser';

@@ -16,7 +16,7 @@ export interface IDidStore {

/**
* DID specification rule for method-specific-id
* DID specification rule for method-specific-id
* DID specification rule for method-name
* The pattern allows an empty identifier to identify a method or did-registry
* See [Issue 34] {@link https://github.com/w3c/did-core/issues/34}
*/
*/
ID: RegExp;

@@ -23,0 +23,0 @@ };

@@ -18,9 +18,9 @@ "use strict";

/**
* DID specification rule for method-specific-id
* DID specification rule for method-specific-id
* DID specification rule for method-name
* The pattern allows an empty identifier to identify a method or did-registry
* See [Issue 34] {@link https://github.com/w3c/did-core/issues/34}
*/
*/
ID: /^[\w.-]*(:[\w.-]*)*$/,
};
//# sourceMappingURL=index.js.map
import { ChainInfo } from '../models';
export declare const didPattern = "^did:[a-z0-9]+?:?[a-z0-9]+?:(0x[A-Fa-f0-9]{40})$";
/**
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
export declare function getDIDMethod(did: string): string;
/**
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
export declare function getDIDChain(did: string): ChainInfo;

@@ -6,7 +6,7 @@ "use strict";

/**
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
function getDIDMethod(did) {

@@ -22,7 +22,7 @@ const match = did.match(exports.didPattern);

/**
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
function getDIDChain(did) {

@@ -29,0 +29,0 @@ const match = did.match(exports.didPattern);

{
"name": "@ew-did-registry/did",
"version": "0.6.3-alpha.403.0",
"version": "0.6.3-alpha.426.0",
"publishConfig": {

@@ -29,3 +29,3 @@ "access": "public",

"devDependencies": {
"@ew-did-registry/keys": "0.6.3-alpha.403.0"
"@ew-did-registry/keys": "0.6.3-alpha.426.0"
},

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

},
"gitHead": "a0a777e6b454a499d5a2afb4953e07e6f615b6d7"
"gitHead": "aa359a33b61b8a3c479f25aa833d0f437239ef96"
}

@@ -72,3 +72,3 @@ import { IDID } from './interface';

// eslint-disable-next-line no-dupe-class-members
set(method: Methods | string, chain?:string, id?: string): IDID {
set(method: Methods | string, chain?: string, id?: string): IDID {
if (method.startsWith('did:')) {

@@ -90,11 +90,14 @@ return this._setDid(method);

if (!DID_SCHEME_PATTERNS.NETWORK.test(`${method}:${chain}`)) {
throw new Error('Network must not be empty and consist only of lowcase alphanumerical characters');
throw new Error(
'Network must not be empty and consist only of lowcase alphanumerical characters'
);
}
if (id !== undefined && !DID_SCHEME_PATTERNS.ID.test(id)) {
throw new Error('Id must consist only of alphanumerical characters, dots, minuses and underscores');
throw new Error(
'Id must consist only of alphanumerical characters, dots, minuses and underscores'
);
}
this._dids.set(method, did);
return this;
}
else {
} else {
const [, method, id] = did.split(':');

@@ -105,6 +108,10 @@ if (id === undefined) {

if (!DID_SCHEME_PATTERNS.NETWORK.test(method)) {
throw new Error('Network must not be empty and consist only of lowcase alphanumerical characters');
throw new Error(
'Network must not be empty and consist only of lowcase alphanumerical characters'
);
}
if (!DID_SCHEME_PATTERNS.ID.test(id)) {
throw new Error('Id must consist only of alphanumerical characters, dots, minuses and underscores');
throw new Error(
'Id must consist only of alphanumerical characters, dots, minuses and underscores'
);
}

@@ -117,10 +124,5 @@ this._dids.set(method, did);

export {
IDID,
DID,
Methods,
Chain,
};
export { IDID, DID, Methods, Chain };
export * from './utils/validation';
export * from './utils/parser';

@@ -1,39 +0,37 @@

import {Methods} from './models';
export interface IDID {
/**
* private members:
* dids: IDidStore;
*/
/**
* private members:
* dids: IDidStore;
*/
/**
* Sets a DID for a particular method (inferred from DID provided)
* @param {string} did
* @returns {void}
*/
set(did: string): IDID;
/**
* Sets a DID for a particular method (inferred from DID provided)
* @param {string} did
* @returns {void}
*/
set(did: string): IDID;
/**
* Sets a DID for the provided method
* @param {Methods} method
* @param {string} id
* @returns {void}
*/
set(method: string, id: string): IDID;
/**
* Sets a DID for the provided method
* @param {Methods} method
* @param {string} id
* @returns {void}
*/
set(method: string, id: string): IDID;
/**
* Sets a DID for the provided method and chain name
* @param {Methods} method
* @param {string} chain
* @param {string} id
* @returns {void}
*/
set(method: string, chain: string, id: string): IDID;
/**
* Sets a DID for the provided method and chain name
* @param {Methods} method
* @param {string} chain
* @param {string} id
* @returns {void}
*/
set(method: string, chain: string, id: string): IDID;
/**
* Gets a DID for a particular method
* @param {Methods} method
* @returns {string | undefined}
*/
get(method: string): string | undefined;
/**
* Gets a DID for a particular method
* @param {Methods} method
* @returns {string | undefined}
*/
get(method: string): string | undefined;
}

@@ -9,3 +9,3 @@ /* eslint-disable no-shadow */

Erc1056 = 'ethr',
Jolocom = 'jolo'
Jolocom = 'jolo',
}

@@ -15,14 +15,13 @@

EWC = 'ewc',
VOLTA = 'volta'
VOLTA = 'volta',
}
export const DID_SCHEME_PATTERNS = {
NETWORK: /^[a-z0-9]+?(:)?[a-z0-9]+?$/,
/**
* DID specification rule for method-specific-id
* DID specification rule for method-specific-id
* DID specification rule for method-name
* The pattern allows an empty identifier to identify a method or did-registry
* See [Issue 34] {@link https://github.com/w3c/did-core/issues/34}
*/
*/
ID: /^[\w.-]*(:[\w.-]*)*$/,

@@ -32,4 +31,4 @@ };

export type ChainInfo = {
foundChainInfo : boolean,
chainInfo : string | undefined
}
foundChainInfo: boolean;
chainInfo: string | undefined;
};

@@ -6,8 +6,8 @@ import { ChainInfo } from '../models';

/**
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
export function getDIDMethod(did : string): string {
* Checks if did is valid and returns the did method
*
* @param did
* @returns {string}
*/
export function getDIDMethod(did: string): string {
const match = did.match(didPattern);

@@ -22,8 +22,8 @@ if (!match) {

/**
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
export function getDIDChain(did : string) : ChainInfo {
* Checks if did is valid and returns the chain did is associated with it
*
* @param did
* @returns {ChainInfo}
*/
export function getDIDChain(did: string): ChainInfo {
const match = did.match(didPattern);

@@ -30,0 +30,0 @@ if (!match) {

@@ -1,9 +0,3 @@

// eslint-disable-next-line import/no-extraneous-dependencies
import { expect } from 'chai';
import {
DID,
IDID,
Methods,
Chain
} from '../src';
import { DID, IDID, Methods, Chain } from '../src';
import { erc1056tests } from './erc1056.testSuit';

@@ -20,3 +14,5 @@

const did = 'did:eth:method_specific_id';
expect(() => { instance.set(did); }).to.not.throw();
expect(() => {
instance.set(did);
}).to.not.throw();
});

@@ -26,3 +22,5 @@

const did = 'did:eth:ewc:method_specific_id';
expect(() => { instance.set(did); }).to.not.throw();
expect(() => {
instance.set(did);
}).to.not.throw();
});

@@ -42,3 +40,5 @@

const did = 'did:mymethod001:';
expect(() => { instance.set(did); }).to.not.throw();
expect(() => {
instance.set(did);
}).to.not.throw();
});

@@ -48,3 +48,5 @@

const did = 'did:mymethod001:ewc:';
expect(() => { instance.set(did); }).to.not.throw();
expect(() => {
instance.set(did);
}).to.not.throw();
});

@@ -54,3 +56,5 @@

const did = 'did:my_method';
expect(() => { instance.set(did); }).to.throw('DID must consist of three parts separated by a colon');
expect(() => {
instance.set(did);
}).to.throw('DID must consist of three parts separated by a colon');
});

@@ -60,5 +64,7 @@

const did = 'did::specific_id';
expect(() => { instance.set(did); })
.to
.throw('Network must not be empty and consist only of lowcase alphanumerical characters');
expect(() => {
instance.set(did);
}).to.throw(
'Network must not be empty and consist only of lowcase alphanumerical characters'
);
});

@@ -68,5 +74,7 @@

const did = 'did:my method:specific_id';
expect(() => { instance.set(did); })
.to
.throw('Network must not be empty and consist only of lowcase alphanumerical characters');
expect(() => {
instance.set(did);
}).to.throw(
'Network must not be empty and consist only of lowcase alphanumerical characters'
);
});

@@ -77,3 +85,5 @@

const id = 'method_specific_id';
expect(() => { instance.set(method, id); }).to.not.throw();
expect(() => {
instance.set(method, id);
}).to.not.throw();
});

@@ -85,3 +95,5 @@

const id = 'method_specific_id';
expect(() => { instance.set(method, chain, id); }).to.not.throw();
expect(() => {
instance.set(method, chain, id);
}).to.not.throw();
});

@@ -92,3 +104,5 @@

const id = 'method_specific_id';
expect(() => { instance.set(method, id); }).to.not.throw();
expect(() => {
instance.set(method, id);
}).to.not.throw();
});

@@ -102,27 +116,25 @@

it(
'Test scenario: setting valid id in both ways should correctly change the state of the DID',
async () => {
instance.set(`did:${Methods.Erc725}:id_in_Ethereum`);
instance.set(Methods.Erc1056, 'id_in_EnergyWeb');
expect(instance.get(Methods.Erc725))
.equals(`did:${Methods.Erc725}:id_in_Ethereum`);
expect(instance.get(Methods.Erc1056))
.equals(`did:${Methods.Erc1056}:id_in_EnergyWeb`);
},
);
it('Test scenario: setting valid id in both ways should correctly change the state of the DID', async () => {
instance.set(`did:${Methods.Erc725}:id_in_Ethereum`);
instance.set(Methods.Erc1056, 'id_in_EnergyWeb');
expect(instance.get(Methods.Erc725)).equals(
`did:${Methods.Erc725}:id_in_Ethereum`
);
expect(instance.get(Methods.Erc1056)).equals(
`did:${Methods.Erc1056}:id_in_EnergyWeb`
);
});
it(
'Test scenario: setting valid id in both ways with chain name should correctly change the state of the DID',
async () => {
instance.set(`did:${Methods.Erc725}:${Chain.EWC}:id_in_Ethereum`);
instance.set(Methods.Erc1056, Chain.EWC, 'id_in_EnergyWeb');
expect(instance.get(Methods.Erc725))
.equals(`did:${Methods.Erc725}:${Chain.EWC}:id_in_Ethereum`);
expect(instance.get(Methods.Erc1056))
.equals(`did:${Methods.Erc1056}:${Chain.EWC}:id_in_EnergyWeb`);
},
);
it('Test scenario: setting valid id in both ways with chain name should correctly change the state of the DID', async () => {
instance.set(`did:${Methods.Erc725}:${Chain.EWC}:id_in_Ethereum`);
instance.set(Methods.Erc1056, Chain.EWC, 'id_in_EnergyWeb');
expect(instance.get(Methods.Erc725)).equals(
`did:${Methods.Erc725}:${Chain.EWC}:id_in_Ethereum`
);
expect(instance.get(Methods.Erc1056)).equals(
`did:${Methods.Erc1056}:${Chain.EWC}:id_in_EnergyWeb`
);
});
describe('Erc1056 tests', erc1056tests);
});

@@ -19,3 +19,5 @@ import { expect } from 'chai';

it('Well-formed did with chain name should be validated', () => {
const did = `did:${Methods.Erc1056}:${Chain.EWC}:${new Keys().getAddress()}`;
const did = `did:${Methods.Erc1056}:${
Chain.EWC
}:${new Keys().getAddress()}`;
expect(isValidErc1056EWC(did)).true;

@@ -34,3 +36,5 @@ });

it('DID method can be retrieved for well formed did with chain name', () => {
const did = `did:${Methods.Erc1056}:${Chain.EWC}:${new Keys().getAddress()}`;
const did = `did:${Methods.Erc1056}:${
Chain.EWC
}:${new Keys().getAddress()}`;
expect(getDIDMethod(did)).equals(Methods.Erc1056);

@@ -40,4 +44,9 @@ });

it('Chain name can be retrieved for well formed did', () => {
const did = `did:${Methods.Erc1056}:${Chain.EWC}:${new Keys().getAddress()}`;
expect(getDIDChain(did)).deep.equal({foundChainInfo : true, chainInfo : Chain.EWC});
const did = `did:${Methods.Erc1056}:${
Chain.EWC
}:${new Keys().getAddress()}`;
expect(getDIDChain(did)).deep.equal({
foundChainInfo: true,
chainInfo: Chain.EWC,
});
});

@@ -47,4 +56,7 @@

const did = `did:${Methods.Erc1056}:${new Keys().getAddress()}`;
expect(getDIDChain(did)).deep.equal({foundChainInfo : false, chainInfo : undefined});
expect(getDIDChain(did)).deep.equal({
foundChainInfo: false,
chainInfo: undefined,
});
});
}

@@ -6,8 +6,4 @@ {

},
"exclude": [
"node_modules"
],
"include": [
"./src/**/*.ts"
]
}
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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