Skip to content

Commit

Permalink
Fix registration names
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Nov 28, 2023
1 parent e9ee9d8 commit 451d5a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
32 changes: 13 additions & 19 deletions src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import {
NetworkName
} from './constants';

export const registerBlockchain = (
name: BlockchainName,
value: BlockchainName | null = null
): void => {
if (Blockchain[name]) {
throw new Error(`blockchain ${name} already registered`);
export const registerBlockchain = (chain: BlockchainName): void => {
if (Blockchain[chain]) {
throw new Error(`blockchain ${chain} already registered`);
}
Blockchain[name] = value ?? name;
Blockchain[chain] = chain;
};

export const registerDidMethodByte = (name: DidMethodName, value: number): void => {
Expand All @@ -29,21 +26,18 @@ export const registerDidMethodByte = (name: DidMethodName, value: number): void
DidMethodByte[name] = value;
};

export const registerDidMethod = (
name: DidMethodName,
value: DidMethodName | null = null
): void => {
if (DidMethod[name]) {
throw new Error(`did method ${name} already registered`);
export const registerDidMethod = (method: DidMethodName): void => {
if (DidMethod[method]) {
throw new Error(`did method ${method} already registered`);
}
DidMethod[name] = value ?? name;
DidMethod[method] = method;
};

export const registerNetworkId = (name: NetworkName, value: NetworkName | null = null): void => {
export const registerNetworkId = (name: NetworkName): void => {
if (NetworkId[name]) {
throw new Error(`network ${name} already registered`);
}
NetworkId[name] = value ?? name;
NetworkId[name] = name;
};

export const registerDidMethodNetwork = (
Expand Down Expand Up @@ -76,9 +70,9 @@ export const registerDidMethodNetwork = (
};

export const registerDidMethodNetworkImplicit = (
method: string,
blockchain: string,
network: string
method: DidMethodName,
blockchain: BlockchainName,
network: NetworkName
): void => {
if (!DidMethod[method]) {
DidMethod[method] = method;
Expand Down
10 changes: 5 additions & 5 deletions tests/did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ describe('DID tests', () => {

it('Custom ParseDID', () => {
// explicitly register all the things
registerBlockchain('Test Chain', 'test_chain');
registerNetworkId('Test Net', 'test_net');
registerDidMethod('Test method', 'test_method');
registerDidMethodByte('Test method', 0b00000011);
registerDidMethodNetwork('Test method', 'Test Chain', 'Test Net', 0b0001_0001);
registerBlockchain('test_chain');
registerNetworkId('test_net');
registerDidMethod('test_method');
registerDidMethodByte('test_method', 0b00000011);
registerDidMethodNetwork('test_method', 'test_chain', 'test_net', 0b0001_0001);
// implicitly register all the things
registerDidMethodNetworkImplicit('method', 'chain', 'network');
registerDidMethodNetworkImplicit('iden3', 'chain', NetworkId.Test);
Expand Down

0 comments on commit 451d5a5

Please sign in to comment.