Skip to content

Commit

Permalink
refactor: move constants
Browse files Browse the repository at this point in the history
  • Loading branch information
eum602 committed Aug 2, 2023
1 parent f1f834e commit 40a1585
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as DID } from "./lib/did.js";
export { default as Lac1DID } from "./lib/lac1/lac1Did.js";
export { default as DIDRecoverable } from "./lib/didrecoverable.js";
export { getResolver as Resolver } from "./lib/resolver.js";
export { getResolver as Lac1Resolver } from "./lib/lac1/resolver.js";
2 changes: 2 additions & 0 deletions lib/lac1/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const LAC1_DID_TYPE_CODE = "0001";
export const LAC1_DID_METHOD_NAME = "lac1";
13 changes: 5 additions & 8 deletions lib/lac1/lac1Did.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import DIDRegistryContract from "./DIDRegistry.json";
import { getResolver } from "./resolver.js";
import Lac1DIDRegistry from "./lac1registry.js";
import basex from "base-x";
import { LAC1_DID_TYPE_CODE, LAC1_DID_METHOD_NAME } from "./constants.js";
export const hex = basex("0123456789abcdef");
export default class DIDLac1 extends DID {
static didMethod = "lac1";
static didType = "0001"; // for "lac1"
didVersion;

constructor(config) {
super(config);
}
Expand Down Expand Up @@ -82,10 +79,10 @@ export default class DIDLac1 extends DID {
get id() {
return (
"did:" +
DIDLac1.didMethod +
LAC1_DID_METHOD_NAME +
":" +
DIDLac1.encode(
DIDLac1.didType,
LAC1_DID_TYPE_CODE,
this.chainId,
this.address,
this.config.registry,
Expand Down Expand Up @@ -137,7 +134,7 @@ export default class DIDLac1 extends DID {
const version = data.subarray(0, 2).toString("hex");
const didType = data.subarray(2, 4).toString("hex");
// TODO handle better versioning
if (didType !== DIDLac1.didType) {
if (didType !== LAC1_DID_TYPE_CODE) {
const message = "Unsupported did type";
throw new Error(message);
}
Expand All @@ -154,7 +151,7 @@ export default class DIDLac1 extends DID {
const chainId = "0x" + c;
return {
address,
didMethod: DIDLac1.didMethod,
didMethod: LAC1_DID_METHOD_NAME,
didRegistryAddress,
chainId,
version,
Expand Down
3 changes: 2 additions & 1 deletion lib/lac1/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DIDRegistryContractGM from "./DIDRegistryGM.json";
import lacchain from "@lacchain/gas-model-provider";
import { wrapDidDocument } from "../resolver.js";
import DIDLac1 from "./lac1Did.js";
import { LAC1_DID_TYPE_CODE } from "./constants.js";

export function getResolver(config = {}) {
const iface = new ethers.utils.Interface(DIDRegistryContractGM.abi);
Expand Down Expand Up @@ -60,7 +61,7 @@ export function getResolver(config = {}) {
registry
);
const encodedController = DIDLac1.encode(
DIDLac1.didType,
LAC1_DID_TYPE_CODE,
decodedDid.chainId,
controller,
decodedDid.didRegistryAddress,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lacchain/did",
"version": "1.6.0",
"version": "1.6.1",
"description": "The LACChain DID Method NodeJS Implementation",
"author": "Sergio Ceron Figueroa <[email protected]>",
"keywords": [
Expand Down

0 comments on commit 40a1585

Please sign in to comment.