diff --git a/docs/api/classes/modules_domains_domains_service.DomainsService.md b/docs/api/classes/modules_domains_domains_service.DomainsService.md index 5ba52118..d85e05ea 100644 --- a/docs/api/classes/modules_domains_domains_service.DomainsService.md +++ b/docs/api/classes/modules_domains_domains_service.DomainsService.md @@ -96,6 +96,7 @@ changeOrgOwnership | `__namedParameters.namespace` | `string` | | `__namedParameters.newOwner` | `string` | | `__namedParameters.returnSteps?` | `boolean` | +| `__namedParameters.withSubdomains?` | `boolean` | #### Returns diff --git a/docs/api/modules/index.md b/docs/api/modules/index.md index 62a5109e..3a7c67a9 100644 --- a/docs/api/modules/index.md +++ b/docs/api/modules/index.md @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/docs/api/modules/utils.md b/docs/api/modules/utils.md index 7fbc0129..a10585fc 100644 --- a/docs/api/modules/utils.md +++ b/docs/api/modules/utils.md @@ -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) @@ -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) diff --git a/docs/api/modules/utils_constants.md b/docs/api/modules/utils_constants.md index 181fc9a8..821e685c 100644 --- a/docs/api/modules/utils_constants.md +++ b/docs/api/modules/utils_constants.md @@ -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) @@ -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`` diff --git a/package-lock.json b/package-lock.json index 534b49bf..9c7f134d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "iam-client-lib", - "version": "4.0.0-alpha.7", + "version": "4.0.0-alpha.10", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/scripts/constants.ts b/scripts/constants.ts new file mode 100644 index 00000000..f1d0cff2 --- /dev/null +++ b/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"; diff --git a/scripts/createEWTree.ts b/scripts/createEWTree.ts new file mode 100644 index 00000000..ff27be17 --- /dev/null +++ b/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`); +})(); diff --git a/scripts/transferEW.ts b/scripts/transferEW.ts new file mode 100644 index 00000000..0ebd9d93 --- /dev/null +++ b/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, + }); +})(); diff --git a/src/config/cache.config.ts b/src/config/cache.config.ts index 3209a65e..e6835a6a 100644 --- a/src/config/cache.config.ts +++ b/src/config/cache.config.ts @@ -3,7 +3,7 @@ import { VOLTA_CHAIN_ID } from "../utils/constants"; const cacheConfig: Record = { [VOLTA_CHAIN_ID]: { - url: "https://volta-identitycache.energyweb.org/v1", + url: "https://identitycache-dev.energyweb.org/v1/", cacheServerSupportsAuth: true, }, }; diff --git a/src/config/chain.config.ts b/src/config/chain.config.ts index 13cad79a..39e0769d 100644 --- a/src/config/chain.config.ts +++ b/src/config/chain.config.ts @@ -35,7 +35,7 @@ const chainConfig: Record = { [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, diff --git a/src/config/messaging.config.ts b/src/config/messaging.config.ts index d8b851ee..502bec68 100644 --- a/src/config/messaging.config.ts +++ b/src/config/messaging.config.ts @@ -11,7 +11,7 @@ export interface MessagingConfig { const messagingConfig: Record = { [VOLTA_CHAIN_ID]: { messagingMethod: MessagingMethod.Nats, - natsServerUrl: "https://volta-identityevents.energyweb.org/", + natsServerUrl: "https://identityevents-dev.energyweb.org/", natsEnvironmentName: "ewf-volta", }, }; diff --git a/src/modules/domains/domains.service.ts b/src/modules/domains/domains.service.ts index cd1b6f05..4d6129c3 100644 --- a/src/modules/domains/domains.service.ts +++ b/src/modules/domains/domains.service.ts @@ -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; @@ -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 = [ @@ -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 = (app).namespace || app; + console.log(`>>> transfering ${namespace} to ${newOwner}`); + await this.changeAppOwnership({ namespace, newOwner, returnSteps }); + } + } } if (alreadyFinished.length > 0) { @@ -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, @@ -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, diff --git a/tsconfig.json b/tsconfig.json index e96422ad..3ab1ec28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" } + } }