Skip to content

Commit

Permalink
feat: scripts to create and transfer energyweb
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Dec 13, 2021
1 parent 9ab11c2 commit b03155d
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 7 deletions.
Expand Up @@ -96,6 +96,7 @@ changeOrgOwnership
| `__namedParameters.namespace` | `string` |
| `__namedParameters.newOwner` | `string` |
| `__namedParameters.returnSteps?` | `boolean` |
| `__namedParameters.withSubdomains?` | `boolean` |

#### Returns

Expand Down
35 changes: 35 additions & 0 deletions docs/api/modules/index.md
Expand Up @@ -25,11 +25,16 @@
- [DeletingNamespaceNotPossibleError](index.md#deletingnamespacenotpossibleerror)
- [DidRegistry](index.md#didregistry)
- [DomainsService](index.md#domainsservice)
- [ENERGYWEB](index.md#energyweb)
- [ENERGYWEB\_OWNER\_DID](index.md#energyweb_owner_did)
- [ENERGYWEB\_ROOT](index.md#energyweb_root)
- [ENSOwnerNotValidAddressError](index.md#ensownernotvalidaddresserror)
- [ENSTypeNotSupportedError](index.md#enstypenotsupportederror)
- [ERROR\_MESSAGES](index.md#error_messages)
- [EWC](index.md#ewc)
- [EkcSigner](index.md#ekcsigner)
- [ExecutionEnvironment](index.md#executionenvironment)
- [IAM](index.md#iam)
- [IApp](index.md#iapp)
- [ICacheClient](index.md#icacheclient)
- [IClaimIssuance](index.md#iclaimissuance)
Expand Down Expand Up @@ -229,6 +234,24 @@ Re-exports: [DomainsService](../classes/modules_domains_domains_service.DomainsS

___

### ENERGYWEB

Re-exports: [ENERGYWEB](utils_constants.md#energyweb)

___

### ENERGYWEB\_OWNER\_DID

Re-exports: [ENERGYWEB\_OWNER\_DID](utils_constants.md#energyweb_owner_did)

___

### ENERGYWEB\_ROOT

Re-exports: [ENERGYWEB\_ROOT](utils_constants.md#energyweb_root)

___

### ENSOwnerNotValidAddressError

Re-exports: [ENSOwnerNotValidAddressError](../classes/errors_ENSOwnerNotValidAddressError.ENSOwnerNotValidAddressError.md)
Expand All @@ -247,6 +270,12 @@ Re-exports: [ERROR\_MESSAGES](../enums/errors_ErrorMessages.ERROR_MESSAGES.md)

___

### EWC

Re-exports: [EWC](utils_constants.md#ewc)

___

### EkcSigner

Re-exports: [EkcSigner](../classes/modules_signer_ekcSigner.EkcSigner.md)
Expand All @@ -259,6 +288,12 @@ Re-exports: [ExecutionEnvironment](../enums/utils_detectEnvironment.ExecutionEnv

___

### IAM

Re-exports: [IAM](utils_constants.md#iam)

___

### IApp

Re-exports: [IApp](../interfaces/modules_domains_domains_types.IApp.md)
Expand Down
35 changes: 35 additions & 0 deletions docs/api/modules/utils.md
Expand Up @@ -4,7 +4,12 @@

### References

- [ENERGYWEB](utils.md#energyweb)
- [ENERGYWEB\_OWNER\_DID](utils.md#energyweb_owner_did)
- [ENERGYWEB\_ROOT](utils.md#energyweb_root)
- [EWC](utils.md#ewc)
- [ExecutionEnvironment](utils.md#executionenvironment)
- [IAM](utils.md#iam)
- [VOLTA\_CHAIN\_ID](utils.md#volta_chain_id)
- [addSupportedDID](utils.md#addsupporteddid)
- [defaultAzureProxyUrl](utils.md#defaultazureproxyurl)
Expand All @@ -17,12 +22,42 @@

## References

### ENERGYWEB

Re-exports: [ENERGYWEB](utils_constants.md#energyweb)

___

### ENERGYWEB\_OWNER\_DID

Re-exports: [ENERGYWEB\_OWNER\_DID](utils_constants.md#energyweb_owner_did)

___

### ENERGYWEB\_ROOT

Re-exports: [ENERGYWEB\_ROOT](utils_constants.md#energyweb_root)

___

### EWC

Re-exports: [EWC](utils_constants.md#ewc)

___

### ExecutionEnvironment

Re-exports: [ExecutionEnvironment](../enums/utils_detectEnvironment.ExecutionEnvironment.md)

___

### IAM

Re-exports: [IAM](utils_constants.md#iam)

___

### VOLTA\_CHAIN\_ID

Re-exports: [VOLTA\_CHAIN\_ID](utils_constants.md#volta_chain_id)
Expand Down
35 changes: 35 additions & 0 deletions docs/api/modules/utils_constants.md
Expand Up @@ -4,6 +4,11 @@

### Variables

- [ENERGYWEB](utils_constants.md#energyweb)
- [ENERGYWEB\_OWNER\_DID](utils_constants.md#energyweb_owner_did)
- [ENERGYWEB\_ROOT](utils_constants.md#energyweb_root)
- [EWC](utils_constants.md#ewc)
- [IAM](utils_constants.md#iam)
- [VOLTA\_CHAIN\_ID](utils_constants.md#volta_chain_id)
- [defaultAzureProxyUrl](utils_constants.md#defaultazureproxyurl)
- [defaultBridgeUrl](utils_constants.md#defaultbridgeurl)
Expand All @@ -12,6 +17,36 @@

## Variables

### ENERGYWEB

`Const` **ENERGYWEB**: ``"energyweb"``

___

### ENERGYWEB\_OWNER\_DID

`Const` **ENERGYWEB\_OWNER\_DID**: ``"did:ethr:volta:0xc56e810fE6715C6c6F0818bb16DAF1fE6A0121e2"``

___

### ENERGYWEB\_ROOT

`Const` **ENERGYWEB\_ROOT**: ``"dmitryfesenko.iam.ewc"``

___

### EWC

`Const` **EWC**: ``"ewc"``

___

### IAM

`Const` **IAM**: ``"iam"``

___

### VOLTA\_CHAIN\_ID

`Const` **VOLTA\_CHAIN\_ID**: ``73799``
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/constants.ts
@@ -0,0 +1,11 @@
export const ewOwnerKey = "1aec3458500362c0a0f1772ab724a71b0f9d7da418a2d86d5954ab3f4b58ec4e";

export const ENERGYWEB = "energyweb";
export const IAM = "iam";
export const EWC = "ewc";
export const ENERGYWEB_ROOT = "tempenergywebowner2.dmitryfesenko.iam.ewc";
// export const ENERGYWEB_ROOT = `${ENERGYWEB}.${IAM}.${EWC}`;
export const ENERGYWEB_OWNER = "did:ethr:volta:0xc56e810fE6715C6c6F0818bb16DAF1fE6A0121e2";
export const KYC_OWNER_DID = "did:ethr:ewc:0x246bDCF1e4f41FC639959FfAC135c77d9844750d";

export const ENERGYWEB_RECEIVER = "did:ethr:volta:0x8556c714BAB801FfB7292Bd73942460e79be83dE";
66 changes: 66 additions & 0 deletions scripts/createEWTree.ts
@@ -0,0 +1,66 @@
import { VOLTA_CHAIN_ID } from "@energyweb/iam-contracts";
import { chainConfigs, initWithPrivateKeySigner } from "../src";
import { ENERGYWEB_OWNER, ENERGYWEB_ROOT, KYC_OWNER_DID } from "./constants";

/**
* Creates apps and roles for the staking use case under the energyweb org
* Assumes that the energyweb org is already created
* For description of roles, see https://energyweb.atlassian.net/wiki/spaces/EWTS/pages/2960228364/SB+setup
*/

const ewOwnerKey = "1aec3458500362c0a0f1772ab724a71b0f9d7da418a2d86d5954ab3f4b58ec4e";
const chainConfig = chainConfigs()[VOLTA_CHAIN_ID];
const rpcUrl = chainConfig.rpcUrl;

(async function () {
const { connectToCacheServer } = await initWithPrivateKeySigner(ewOwnerKey, rpcUrl);
const { domainsService } = await connectToCacheServer();

const stakingApp = "staking";
await domainsService.createApplication({
appName: stakingApp,
namespace: `apps.${ENERGYWEB_ROOT}`,
data: { appName: stakingApp, websiteUrl: "https://staking-staging.energyweb.org/" },
});
console.log(`Application ${stakingApp} is created`);
const verificationApp = "verification";
await domainsService.createApplication({
appName: verificationApp,
namespace: `apps.${ENERGYWEB_ROOT}`,
data: { appName: verificationApp },
});
console.log(`Application ${verificationApp} is created`);
console.log("apps of energyweb root:", await domainsService.getAppsOfOrg(ENERGYWEB_ROOT));

const stakingOwnerRole = "owner";
await domainsService.createRole({
roleName: stakingOwnerRole,
namespace: `roles.${stakingApp}.apps.${ENERGYWEB_ROOT}`,
data: {
roleName: stakingOwnerRole,
roleType: "app",
version: 1,
enrolmentPreconditions: [],
fields: [],
metadata: {},
issuer: { issuerType: "DID", did: [ENERGYWEB_OWNER] },
},
});
console.log(`Role ${stakingOwnerRole} is created`);

const emailRole = "email";
await domainsService.createRole({
roleName: emailRole,
namespace: `roles.${verificationApp}.apps.${ENERGYWEB_ROOT}`,
data: {
roleName: emailRole,
roleType: "app",
version: 1,
enrolmentPreconditions: [],
fields: [],
metadata: {},
issuer: { issuerType: "DID", did: [ENERGYWEB_OWNER, KYC_OWNER_DID] },
},
});
console.log(`Role ${emailRole} is created`);
})();
16 changes: 16 additions & 0 deletions scripts/transferEW.ts
@@ -0,0 +1,16 @@
import { addressOf } from "@ew-did-registry/did-ethr-resolver";
import { chainConfigs, initWithPrivateKeySigner, VOLTA_CHAIN_ID } from "../src";
import { ENERGYWEB_RECEIVER, ENERGYWEB_ROOT, ewOwnerKey } from "./constants";

const rpcUrl = chainConfigs()[VOLTA_CHAIN_ID].rpcUrl;

(async function () {
const { connectToCacheServer } = await initWithPrivateKeySigner(ewOwnerKey, rpcUrl);
const { domainsService } = await connectToCacheServer();
await domainsService.changeOrgOwnership({
namespace: ENERGYWEB_ROOT,
newOwner: addressOf(ENERGYWEB_RECEIVER),
returnSteps: false,
withSubdomains: true,
});
})();
2 changes: 1 addition & 1 deletion src/config/cache.config.ts
Expand Up @@ -3,7 +3,7 @@ import { VOLTA_CHAIN_ID } from "../utils/constants";

const cacheConfig: Record<number, CacheServerClientOptions> = {
[VOLTA_CHAIN_ID]: {
url: "https://volta-identitycache.energyweb.org/v1",
url: "https://identitycache-dev.energyweb.org/v1/",
cacheServerSupportsAuth: true,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/config/chain.config.ts
Expand Up @@ -35,7 +35,7 @@ const chainConfig: Record<number, ChainConfig> = {
[VOLTA_CHAIN_ID]: {
chainName: Chain.VOLTA,
chainDisplayName: "Energy Web Volta Testnet",
rpcUrl: "https://volta-rpc.energyweb.org",
rpcUrl: "https://volta-rpc-vkn5r5zx4ke71f9hcu0c.energyweb.org/",
ensRegistryAddress: VOLTA_ENS_REGISTRY_ADDRESS,
ensResolverAddress: VOLTA_RESOLVER_V1_ADDRESS,
ensPublicResolverAddress: VOLTA_PUBLIC_RESOLVER_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion src/config/messaging.config.ts
Expand Up @@ -11,7 +11,7 @@ export interface MessagingConfig {
const messagingConfig: Record<ChainId, MessagingConfig> = {
[VOLTA_CHAIN_ID]: {
messagingMethod: MessagingMethod.Nats,
natsServerUrl: "https://volta-identityevents.energyweb.org/",
natsServerUrl: "https://identityevents-dev.energyweb.org/",
natsEnvironmentName: "ewf-volta",
},
};
Expand Down
17 changes: 15 additions & 2 deletions src/modules/domains/domains.service.ts
Expand Up @@ -26,6 +26,7 @@ import { RegistrationTypes } from "../claims/claims.types";
import { SignerService } from "../signer/signer.service";
import { NamespaceType, IOrganization } from "./domains.types";
import { SearchType } from "../cacheClient/cacheClient.types";
import { IApp } from ".";
import { validateAddress } from "../../utils/address";

const { namehash } = utils;
Expand Down Expand Up @@ -313,10 +314,12 @@ export class DomainsService {
namespace,
newOwner,
returnSteps = false,
withSubdomains = false,
}: {
namespace: string;
newOwner: string;
returnSteps?: boolean;
withSubdomains?: boolean;
}) {
DomainsService.validateOwnerAddress(newOwner);
const orgNamespaces = [
Expand All @@ -339,7 +342,15 @@ export class DomainsService {
domain: `${NamespaceType.Application}.${namespace}`,
});
if (apps && apps.length > 0) {
throw new Error("You are not able to change ownership of organization with registered apps");
if (!withSubdomains) {
throw new Error("You are not able to change ownership of organization with registered apps");
} else {
for await (const app of apps) {
const namespace = (<IApp>app).namespace || <string>app;
console.log(`>>> transfering ${namespace} to ${newOwner}`);
await this.changeAppOwnership({ namespace, newOwner, returnSteps });
}
}
}

if (alreadyFinished.length > 0) {
Expand Down Expand Up @@ -388,7 +399,8 @@ export class DomainsService {
returnSteps?: boolean;
}) {
DomainsService.validateOwnerAddress(newOwner);
const appNamespaces = [`${NamespaceType.Role}.${namespace}`, namespace];
const roles = await this.getRolesByNamespace({ namespace, parentType: NamespaceType.Application });
const appNamespaces = [...roles.map((r) => r.namespace), `${NamespaceType.Role}.${namespace}`, namespace];

const { alreadyFinished, changeOwnerNamespaces, notOwnedNamespaces } = await this.validateChangeOwnership({
newOwner,
Expand All @@ -404,6 +416,7 @@ export class DomainsService {
}

const steps = changeOwnerNamespaces.map((namespace) => {
console.log(`>>> transfering ${namespace} to ${newOwner}`);
const tx = this.changeDomainOwnerTx({ newOwner, namespace });
return {
tx,
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Expand Up @@ -32,5 +32,8 @@
"suppressImplicitAnyIndexErrors": true,
"target": "es6"
},
"include": ["src/**/*", "ethers/**/*", "test/**/*", "e2e/**/*.ts"]
"include": ["src/**/*", "ethers/**/*", "test/**/*", "e2e/**/*.ts"],
"ts-node": {
"compilerOptions": { "module": "CommonJS" }
}
}

0 comments on commit b03155d

Please sign in to comment.