diff --git a/examples/verify-credential.js b/examples/verify-credential.js index 1b0049a5..d4c1550f 100644 --- a/examples/verify-credential.js +++ b/examples/verify-credential.js @@ -6,7 +6,7 @@ const { didServiceRPC, } = require('@docknetwork/wallet-sdk-wasm/src/services/dids'); -const {dockService} = require('@docknetwork/wallet-sdk-wasm/src/services/dock'); +const {blockchainService} = require('@docknetwork/wallet-sdk-wasm/src/services/blockchain'); const exampleCredential = require('./example-credential.json'); const presentationDefinition = require('./presentation-definition.json'); @@ -19,7 +19,7 @@ async function main() { console.log('Connecting to dock network'); - await dockService.ensureDockReady(); + await blockchainService.ensureBlockchainReady(); // generate new DID const keyDoc = await didServiceRPC.generateKeyDoc({}); diff --git a/integration-tests/verification-flow/bbs-plus-expired.test.ts b/integration-tests/verification-flow/bbs-plus-expired.test.ts index 20525051..cd779639 100644 --- a/integration-tests/verification-flow/bbs-plus-expired.test.ts +++ b/integration-tests/verification-flow/bbs-plus-expired.test.ts @@ -4,7 +4,7 @@ import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/ver import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations'; import assert from 'assert'; import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index'; -import { dockService } from '@docknetwork/wallet-sdk-wasm/src/services/dock'; +import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain'; const testAPIURL = process.env.TESTING_API_URL || null; @@ -129,7 +129,7 @@ describe('BBS+ presentations', () => { const verificationResults = await verifyPresentation(presentation, { compactProof: true, - resolver: dockService.resolver, + resolver: blockchainService.resolver, challenge: proofRequest.nonce, unsignedPresentation: true, domain: 'dock.io', diff --git a/integration-tests/verification-flow/sales-demo-auto-loan.test.ts b/integration-tests/verification-flow/sales-demo-auto-loan.test.ts index 45793093..68ede911 100644 --- a/integration-tests/verification-flow/sales-demo-auto-loan.test.ts +++ b/integration-tests/verification-flow/sales-demo-auto-loan.test.ts @@ -2,7 +2,7 @@ import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types'; import {closeWallet, getWallet} from '../helpers/wallet-helpers'; import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/verification-controller'; import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain'; import {autoLoanProofRequest} from './proof-requests'; const biometricCredential = { @@ -344,7 +344,7 @@ describe('BBS+ presentations', () => { const verificationResults = await verifyPresentation(presentation, { compactProof: true, - resolver: dockService.resolver, + resolver: blockchainService.resolver, challenge: proofRequest.nonce, unsignedPresentation: true, domain: 'dock.io', diff --git a/packages/cli/src/commands/ecosystem.ts b/packages/cli/src/commands/ecosystem.ts index c86d445f..cb30b8c5 100644 --- a/packages/cli/src/commands/ecosystem.ts +++ b/packages/cli/src/commands/ecosystem.ts @@ -1,6 +1,6 @@ import {Command} from 'commander'; import {typedHexDID} from '@docknetwork/sdk/utils/did/typed-did/helpers'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock/service'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service'; import {getWallet} from '../helpers'; import {getDIDKeyPairs} from '@docknetwork/wallet-sdk-core/src/did-provider'; import {randomAsHex} from '@polkadot/util-crypto'; @@ -18,26 +18,26 @@ ecosystemCommands const didKeyPairs = await getDIDKeyPairs({wallet}); const didKeyPair = didKeyPairs[0]; - await dockService.init({ + await blockchainService.init({ address: 'wss://knox-1.dock.io', }); - await dockService.waitDockReady(); - await dockService.ensureDockReady(); + await blockchainService.waitDockReady(); + await blockchainService.ensureBlockchainReady(); const trustRegistryId = randomAsHex(32); - const trustRegistry = await dockService.dock.trustRegistry.initOrUpdate( + const trustRegistry = await blockchainService.dock.trustRegistry.initOrUpdate( didKeyPair.id, trustRegistryId, 'Test Registry II', 'Gov framework II', didKeyPair, - dockService.dock, + blockchainService.dock, ); console.log(trustRegistry); - await dockService.disconnect(); + await blockchainService.disconnect(); }); ecosystemCommands @@ -45,23 +45,23 @@ ecosystemCommands .option('-d, --did ', 'DID') .description('Get ecosystem from issuer DID') .action(async ({did}) => { - await dockService.init({ + await blockchainService.init({ address: 'wss://knox-1.dock.io', }); - await dockService.waitDockReady(); - await dockService.ensureDockReady(); + await blockchainService.waitDockReady(); + await blockchainService.ensureBlockchainReady(); const issuerDIDMethodKey = typedHexDID( - dockService.dock.api, + blockchainService.dock.api, did, ); - const registryInfo = await dockService.dock.trustRegistry?.registriesInfo({ + const registryInfo = await blockchainService.dock.trustRegistry?.registriesInfo({ Issuer: issuerDIDMethodKey, }); console.log(registryInfo); - await dockService.disconnect(); + await blockchainService.disconnect(); }); export {ecosystemCommands}; diff --git a/packages/core/src/credential-provider.ts b/packages/core/src/credential-provider.ts index 40bdb37b..148123ff 100644 --- a/packages/core/src/credential-provider.ts +++ b/packages/core/src/credential-provider.ts @@ -1,7 +1,7 @@ import {credentialServiceRPC} from '@docknetwork/wallet-sdk-wasm/src/services/credential'; import {IWallet} from './types'; import assert from 'assert'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain'; import {acquireOpenIDCredentialFromURI} from './credentials/oidvc'; import {IDIDProvider} from './did-provider'; @@ -259,7 +259,7 @@ async function syncCredentialStatus({ } if (!isApiConnected) { - await dockService.ensureDockReady(); + await blockchainService.ensureBlockchainReady(); isApiConnected = true; } diff --git a/packages/core/src/wallet-wasm.ts b/packages/core/src/wallet-wasm.ts index 83ebfcc3..19a8c291 100644 --- a/packages/core/src/wallet-wasm.ts +++ b/packages/core/src/wallet-wasm.ts @@ -1,4 +1,4 @@ -import { dockService } from '@docknetwork/wallet-sdk-wasm/src/services/dock'; +import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain'; import { keyringService } from '@docknetwork/wallet-sdk-wasm/src/services/keyring'; import { utilCryptoService } from '@docknetwork/wallet-sdk-wasm/src/services/util-crypto'; @@ -7,8 +7,8 @@ import { WalletEvents } from '@docknetwork/wallet-sdk-wasm/src/modules/wallet'; import { captureException } from './helpers'; import { IWallet } from './types'; -function isSubstrateNetwork(network: Network) { - return !!network.configs.substrateUrl; +function isBlockchainNetwork(network: Network) { + return !!(network.configs.substrateUrl || network.configs.cheqdApiUrl); } /** @@ -16,24 +16,24 @@ function isSubstrateNetwork(network: Network) { * Compare connected substrate connection with the current walle network * Disconnect and Establish a new connection if the network is different */ -export async function handleSubstrateNetworkChange( +export async function handleBlockchainNetworkChange( wallet: IWallet, ): Promise { - const currentSubstrateAddress = await dockService.getAddress(); - const substrateNetworkId = wallet.dataStore.networks.find( - network => network.configs.substrateUrl === currentSubstrateAddress, + const currentAddress = await blockchainService.getAddress(); + const networkId = wallet.dataStore.networks.find( + network => network.configs.substrateUrl === currentAddress || network.configs.cheqdApiUrl === currentAddress, )?.id; const currentNetworkId = wallet.dataStore.network?.id; - if (substrateNetworkId === currentNetworkId) { + if (networkId === currentNetworkId) { return; } - await dockService.disconnect(); - await setSubstrateNetwork(wallet); + await blockchainService.disconnect(); + await setBlockchainNetwork(wallet); } -export async function setSubstrateNetwork(wallet: IWallet) { +export async function setBlockchainNetwork(wallet: IWallet) { const network = wallet.dataStore.network; const networkConfigs = network.configs; @@ -53,7 +53,7 @@ export async function setSubstrateNetwork(wallet: IWallet) { ss58Format: networkConfigs.addressPrefix, }); - dockService + blockchainService .init({ address: networkConfigs.substrateUrl, cheqdApiUrl: networkConfigs.cheqdApiUrl, @@ -75,11 +75,11 @@ export async function initWalletWasm(wallet: IWallet) { await utilCryptoService.cryptoWaitReady(); const network = wallet.dataStore.network; - if (isSubstrateNetwork(network)) { - await setSubstrateNetwork(wallet); + if (isBlockchainNetwork(network)) { + await setBlockchainNetwork(wallet); wallet.eventManager.on(WalletEvents.networkUpdated, async () => { - handleSubstrateNetworkChange(wallet).catch(err => console.error(err)); + handleBlockchainNetworkChange(wallet).catch(err => console.error(err)); }); } diff --git a/packages/relay-service/src/did/dids.js b/packages/relay-service/src/did/dids.js index 2ec926df..80273b44 100644 --- a/packages/relay-service/src/did/dids.js +++ b/packages/relay-service/src/did/dids.js @@ -1,5 +1,5 @@ import {hexDIDToQualified} from '@docknetwork/sdk/utils/did'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock/service'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service'; export async function resolveDID(did, disableCache = false) { // Check if string has no qualifier, if so assume its hex format @@ -14,5 +14,5 @@ export async function resolveDID(did, disableCache = false) { } } - return await dockService.resolver.resolve(qualifiedDID, disableCache); + return await blockchainService.resolver.resolve(qualifiedDID, disableCache); } diff --git a/packages/relay-service/src/index.js b/packages/relay-service/src/index.js index 069319dc..c4ace9b9 100644 --- a/packages/relay-service/src/index.js +++ b/packages/relay-service/src/index.js @@ -16,7 +16,7 @@ import { toBase64, } from './payloads'; import jwtDecode from 'jwt-decode'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock/service'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service'; let serviceURL = process.env.RELAY_SERVICE_URL || 'https://relay.dock.io'; @@ -68,7 +68,7 @@ const getMessages = async ({ assert(Array.isArray(keyPairDocs), 'keyPairDocs must be an array'); assert(!!keyPairDocs.length, 'keyPairDocs must not be empty'); - await dockService.waitDockReady(); + await blockchainService.waitDockReady(); const {payload, dids} = await generateSignedPayloadFromList(keyPairDocs, { limit, diff --git a/packages/relay-service/tests/didcomm.test.js b/packages/relay-service/tests/didcomm.test.js index 44bab07e..7e7a1be0 100644 --- a/packages/relay-service/tests/didcomm.test.js +++ b/packages/relay-service/tests/didcomm.test.js @@ -5,7 +5,7 @@ import { getDerivedAgreementKey, } from '../lib/didcomm'; import {ALICE_KEY_PAIR_DOC, BOB_KEY_PAIR_DOC} from './mock-data'; -import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock/service'; +import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service'; import {WildcardMultiResolver} from '@docknetwork/sdk/resolver'; const didList = [ALICE_KEY_PAIR_DOC, BOB_KEY_PAIR_DOC]; @@ -34,12 +34,12 @@ const mockDIDResolver = new WalletSDKResolver([ // new UniversalResolver(universalResolverUrl), ]); -dockService.createDIDResolver = () => mockDIDResolver; -dockService.resolver = mockDIDResolver; +blockchainService.createDIDResolver = () => mockDIDResolver; +blockchainService.resolver = mockDIDResolver; describe('DIDComm', () => { it('expect to decrypt didcomm message', async () => { - dockService.resolver = mockDIDResolver; + blockchainService.resolver = mockDIDResolver; const keyAgreementKey = await getDerivedAgreementKey(ALICE_KEY_PAIR_DOC); diff --git a/packages/wasm/src/services/dock/configs.ts b/packages/wasm/src/services/blockchain/configs.ts similarity index 84% rename from packages/wasm/src/services/dock/configs.ts rename to packages/wasm/src/services/blockchain/configs.ts index 92d111da..216fae63 100644 --- a/packages/wasm/src/services/dock/configs.ts +++ b/packages/wasm/src/services/blockchain/configs.ts @@ -9,7 +9,7 @@ export const validation = { export type InitParams = { address: string, - cheqdApiUrl: string, - networkId: string, + cheqdApiUrl?: string, + networkId?: string, cheqdMnemonic?: string, }; diff --git a/packages/wasm/src/services/blockchain/index.android.js b/packages/wasm/src/services/blockchain/index.android.js new file mode 100644 index 00000000..5959cd79 --- /dev/null +++ b/packages/wasm/src/services/blockchain/index.android.js @@ -0,0 +1,3 @@ +import {BlockchainServiceRpc} from './service-rpc'; + +export const blockchainService = new BlockchainServiceRpc(); \ No newline at end of file diff --git a/packages/wasm/src/services/blockchain/index.ios.js b/packages/wasm/src/services/blockchain/index.ios.js new file mode 100644 index 00000000..e544fe17 --- /dev/null +++ b/packages/wasm/src/services/blockchain/index.ios.js @@ -0,0 +1,3 @@ +import {BlockchainServiceRpc} from './service-rpc'; + +export const blockchainService = new BlockchainServiceRpc(); diff --git a/packages/wasm/src/services/blockchain/index.js b/packages/wasm/src/services/blockchain/index.js new file mode 100644 index 00000000..58aa85e3 --- /dev/null +++ b/packages/wasm/src/services/blockchain/index.js @@ -0,0 +1 @@ +export {blockchainService} from './service'; diff --git a/packages/wasm/src/services/dock/index.test.js b/packages/wasm/src/services/blockchain/index.test.js similarity index 87% rename from packages/wasm/src/services/dock/index.test.js rename to packages/wasm/src/services/blockchain/index.test.js index a90d3b07..86282e98 100644 --- a/packages/wasm/src/services/dock/index.test.js +++ b/packages/wasm/src/services/blockchain/index.test.js @@ -5,8 +5,8 @@ import { mockDockSdkConnection, } from '../test-utils'; import {validation} from './configs'; -import {dockService as service} from './service'; -import {DockServiceRpc} from './service-rpc'; +import {blockchainService as service} from './service'; +import {BlockchainServiceRpc} from './service-rpc'; const doConnect = ( address = NetworkManager.getInstance().getNetworkInfo().substrateUrl, @@ -17,7 +17,7 @@ const doConnect = ( describe('DockService', () => { it('ServiceRpc', () => { - assertRpcService(DockServiceRpc, service, validation); + assertRpcService(BlockchainServiceRpc, service, validation); }); describe('init', () => { diff --git a/packages/wasm/src/services/dock/service-rpc.js b/packages/wasm/src/services/blockchain/service-rpc.js similarity index 76% rename from packages/wasm/src/services/dock/service-rpc.js rename to packages/wasm/src/services/blockchain/service-rpc.js index 4cf4e7eb..ac2f6de3 100644 --- a/packages/wasm/src/services/dock/service-rpc.js +++ b/packages/wasm/src/services/blockchain/service-rpc.js @@ -4,9 +4,9 @@ import {InitParams, validation} from './configs'; /** * */ -export class DockServiceRpc extends RpcService { +export class BlockchainServiceRpc extends RpcService { constructor() { - super('dock'); + super('blockchain'); } /** @@ -19,8 +19,8 @@ export class DockServiceRpc extends RpcService { /** * */ - ensureDockReady(): Promise { - return this.call('ensureDockReady'); + ensureBlockchainReady(): Promise { + return this.call('ensureBlockchainReady'); } /** diff --git a/packages/wasm/src/services/dock/service.ts b/packages/wasm/src/services/blockchain/service.ts similarity index 91% rename from packages/wasm/src/services/dock/service.ts rename to packages/wasm/src/services/blockchain/service.ts index 141410c1..486d8fa8 100644 --- a/packages/wasm/src/services/dock/service.ts +++ b/packages/wasm/src/services/blockchain/service.ts @@ -40,7 +40,7 @@ class AnyDIDResolver extends ResolverRouter { /** * */ -export class DockService { +export class BlockchainService { dock; modules; didModule; @@ -48,12 +48,12 @@ export class DockService { isDockReady = false; resolver: any; static Events = { - DOCK_READY: 'dock-ready', + BLOCKCHAIN_READY: 'blockchain-ready', }; rpcMethods = [ DockService.prototype.disconnect, - DockService.prototype.ensureDockReady, + DockService.prototype.ensureBlockchainReady, DockService.prototype.init, DockService.prototype.isApiConnected, DockService.prototype.getAddress, @@ -77,12 +77,12 @@ export class DockService { * * @returns */ - async ensureDockReady() { + async ensureBlockchainReady() { if (this.isDockReady) { return; } - return once(this.emitter, DockService.Events.DOCK_READY); + return once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY); } createDIDResolver() { @@ -164,7 +164,7 @@ export class DockService { if (this.isDockReady) { resolve(); } else { - this.emitter.once(DockService.Events.DOCK_READY, resolve); + this.emitter.once(BlockchainService.Events.BLOCKCHAIN_READY, resolve); } }); } @@ -190,4 +190,4 @@ export class DockService { } } -export const dockService: DockService = new DockService(); +export const blockchainService: BlockchainService = new BlockchainService(); diff --git a/packages/wasm/src/services/credential/bbs-revocation.ts b/packages/wasm/src/services/credential/bbs-revocation.ts index 378ad7ab..62b4de28 100644 --- a/packages/wasm/src/services/credential/bbs-revocation.ts +++ b/packages/wasm/src/services/credential/bbs-revocation.ts @@ -9,7 +9,7 @@ import { } from '@docknetwork/crypto-wasm-ts'; import {hexToU8a} from '@polkadot/util'; -import { dockService } from '../dock/service'; +import {blockchainService} from '../blockchain/service'; const trimHexID = id => { if (id.substr(0, 2) !== '0x') { @@ -38,7 +38,7 @@ async function updateMembershipWitness({ try { // TODO: Ensure it will for cheqd // Will be handled on https://dock-team.atlassian.net/browse/DCKW-572 - updates = await dockService.modules.accumulator.dockOnly.getUpdatesFromBlock( + updates = await blockchainService.modules.accumulator.dockOnly.getUpdatesFromBlock( registryId, blockNo, ); @@ -99,7 +99,7 @@ export const getWitnessDetails = async (credential, _membershipWitness) => { const registryId = credentialStatus?.id.replace('dock:accumulator:', ''); const revocationIndex = credentialStatus.revocationId; - const queriedAccumulator = await dockService.modules.accumulator.getAccumulator( + const queriedAccumulator = await blockchainService.modules.accumulator.getAccumulator( registryId, false, ); @@ -112,7 +112,7 @@ export const getWitnessDetails = async (credential, _membershipWitness) => { const encodedRevId = Encoder.defaultEncodeFunc()(revocationIndex.toString()); - const publicKey = await dockService.modules.accumulator.getPublicKey( + const publicKey = await blockchainService.modules.accumulator.getPublicKey( queriedAccumulator.keyRef[0], queriedAccumulator.keyRef[1], ); diff --git a/packages/wasm/src/services/credential/service.ts b/packages/wasm/src/services/credential/service.ts index ace33b61..4c7d9fb9 100644 --- a/packages/wasm/src/services/credential/service.ts +++ b/packages/wasm/src/services/credential/service.ts @@ -19,7 +19,7 @@ import Presentation from '@docknetwork/sdk/presentation'; import {verifyCredential} from '@docknetwork/sdk/utils/vc/credentials'; import {PEX} from '@sphereon/pex'; import {keyDocToKeypair} from './utils'; -import {dockService, getDock} from '../dock/service'; +import {blockchainService, getDock} from '../blockchain/service'; import { applyEnforceBounds, hasProvingKey, @@ -123,13 +123,13 @@ class CredentialService { return vp.toJSON(); } - return vp.sign(keyDoc, challenge, domain, dockService.resolver); + return vp.sign(keyDoc, challenge, domain, blockchainService.resolver); } async verifyCredential(params) { validation.verifyCredential(params); const {credential, membershipWitness} = params; const result = await verifyCredential(credential, { - resolver: dockService.resolver, + resolver: blockchainService.resolver, revocationApi: {dock: getDock()}, }); @@ -265,7 +265,7 @@ class CredentialService { const bbsPlusPresentation = new Presentation(); for (const {credential, attributesToReveal} of credentials) { const idx = await bbsPlusPresentation.addCredentialToPresent(credential, { - resolver: dockService.resolver, + resolver: blockchainService.resolver, }); if (Array.isArray(attributesToReveal) && attributesToReveal.length > 0) { await bbsPlusPresentation.addAttributeToReveal(idx, attributesToReveal); @@ -359,7 +359,7 @@ class CredentialService { for (const {credential} of credentials) { await presentation.addCredentialToPresent(credential, { - resolver: dockService.resolver, + resolver: blockchainService.resolver, }); } diff --git a/packages/wasm/src/services/dids/index.test.js b/packages/wasm/src/services/dids/index.test.js index 098348a4..9cf028c3 100644 --- a/packages/wasm/src/services/dids/index.test.js +++ b/packages/wasm/src/services/dids/index.test.js @@ -5,7 +5,7 @@ import {validation} from './config'; import {DIDKeyManager} from '@docknetwork/wallet-sdk-dids/src'; import {TestFixtures} from '../../fixtures'; import {getTestWallet} from '../../test/setup-test-state'; -import {dockService, getDock} from '../dock/service'; +import {blockchainService, getDock} from '../blockchain/service'; import {DockDid} from '@docknetwork/credential-sdk/types'; describe('DID Service', () => { @@ -100,7 +100,7 @@ describe('DID Service', () => { }); it('expect to register did dock', async () => { - dockService.modules = { + blockchainService.modules = { did: { dockOnly: { rawTx: { @@ -120,7 +120,7 @@ describe('DID Service', () => { }); it('expect to fail to register did dock', async () => { - dockService.modules = { + blockchainService.modules = { did: { dockOnly: { rawTx: { diff --git a/packages/wasm/src/services/dids/service.ts b/packages/wasm/src/services/dids/service.ts index 1b337a0d..0322344c 100644 --- a/packages/wasm/src/services/dids/service.ts +++ b/packages/wasm/src/services/dids/service.ts @@ -9,7 +9,7 @@ import { import {keyringService} from '../keyring/service'; import {utilCryptoService} from '../util-crypto/service'; import assert from 'assert'; -import {dockService, getDock} from '../dock/service'; +import {blockchainService, getDock} from '../blockchain/service'; import { DidKey, @@ -35,7 +35,7 @@ async function createDockDID({keyPair}) { const verRels = new VerificationRelationship(); const didKey = new DidKey(publicKey, verRels); - await dockService.modules.did.dockOnly.rawTx.newOnchain( + await blockchainService.modules.did.dockOnly.rawTx.newOnchain( dockDID.did, [didKey], dockController === dockDID.toString() @@ -48,7 +48,7 @@ async function createDockDID({keyPair}) { async function getSignerKeypair(privateKeyDoc) { const privateKey = - privateKeyDoc.keypair || keyDocToKeypair(privateKeyDoc, dockService.dock); + privateKeyDoc.keypair || keyDocToKeypair(privateKeyDoc, blockchainService.dock); if (!privateKey.signer && privateKey.sign) { privateKey.signer = () => ({sign: ({data}) => privateKey.sign(data)}); diff --git a/packages/wasm/src/services/dock/index.android.js b/packages/wasm/src/services/dock/index.android.js deleted file mode 100644 index 49fdb182..00000000 --- a/packages/wasm/src/services/dock/index.android.js +++ /dev/null @@ -1,3 +0,0 @@ -import {DockServiceRpc} from './service-rpc'; - -export const dockService = new DockServiceRpc(); diff --git a/packages/wasm/src/services/dock/index.ios.js b/packages/wasm/src/services/dock/index.ios.js deleted file mode 100644 index 49fdb182..00000000 --- a/packages/wasm/src/services/dock/index.ios.js +++ /dev/null @@ -1,3 +0,0 @@ -import {DockServiceRpc} from './service-rpc'; - -export const dockService = new DockServiceRpc(); diff --git a/packages/wasm/src/services/dock/index.js b/packages/wasm/src/services/dock/index.js deleted file mode 100644 index ecdef395..00000000 --- a/packages/wasm/src/services/dock/index.js +++ /dev/null @@ -1 +0,0 @@ -export {dockService} from './service'; diff --git a/packages/wasm/src/services/index.js b/packages/wasm/src/services/index.js index 42cb201e..7cf92e88 100644 --- a/packages/wasm/src/services/index.js +++ b/packages/wasm/src/services/index.js @@ -1,5 +1,5 @@ import {keyringService} from './keyring/service'; -import {dockService} from './dock/service'; +import {blockchainService} from './blockchain/service'; import {substrateService} from './substrate/service'; import {walletService} from './wallet/service'; import {polkadotService} from './polkadot/service'; @@ -14,7 +14,7 @@ import {edvService} from './edv/service'; export default [ keyringService, - dockService, + blockchainService, substrateService, walletService, polkadotService, diff --git a/packages/wasm/src/services/substrate/api-utils.test.js b/packages/wasm/src/services/substrate/api-utils.test.js index 755a8e9b..80d13ade 100644 --- a/packages/wasm/src/services/substrate/api-utils.test.js +++ b/packages/wasm/src/services/substrate/api-utils.test.js @@ -1,7 +1,7 @@ import {DOCK_TOKEN_UNIT} from '../../core/format-utils'; import {TestFixtures} from '../../fixtures'; import {once} from '../../modules/event-manager'; -import {dockService} from '../dock/service'; +import {blockchainService} from '../blockchain/service'; import {mockDockService, setMockTransactionError} from '../test-utils'; import {signAndSend} from './api-utils'; import {substrateService} from './service'; @@ -16,8 +16,8 @@ describe('ApiUtils', () => { describe('signAndSend', () => { it('expect to send tokens', async () => { const account = TestFixtures.account1.getKeyring(); - dockService.dock.setAccount(account); - const extrinsic = dockService.dock.api.tx.balances.transfer( + blockchainService.dock.setAccount(account); + const extrinsic = blockchainService.dock.api.tx.balances.transfer( TestFixtures.account2.address, 1, ); @@ -32,8 +32,8 @@ describe('ApiUtils', () => { it('expect to get error: Inability to pay fees', async () => { const account = TestFixtures.noBalanceAccount.getKeyring(); - dockService.dock.setAccount(account); - const extrinsic = dockService.dock.api.tx.balances.transfer( + blockchainService.dock.setAccount(account); + const extrinsic = blockchainService.dock.api.tx.balances.transfer( TestFixtures.account2.address, 1, ); @@ -49,11 +49,11 @@ describe('ApiUtils', () => { it('expect to get error: Not enough balance', async () => { const account = TestFixtures.account1.getKeyring(); - dockService.dock.setAccount(account); + blockchainService.dock.setAccount(account); const balance = await substrateService.getAccountBalance({ address: TestFixtures.account1.address, }); - const extrinsic = dockService.dock.api.tx.balances.transfer( + const extrinsic = blockchainService.dock.api.tx.balances.transfer( TestFixtures.account2.address, balance * 2 * DOCK_TOKEN_UNIT, ); diff --git a/packages/wasm/src/services/substrate/api-utils.ts b/packages/wasm/src/services/substrate/api-utils.ts index cc82c4da..da82e66a 100644 --- a/packages/wasm/src/services/substrate/api-utils.ts +++ b/packages/wasm/src/services/substrate/api-utils.ts @@ -2,10 +2,10 @@ import assert from 'assert'; import {EventEmitter} from 'events'; import {Logger} from '../../core/logger'; -import {dockService} from '../dock/service'; +import {blockchainService} from '../blockchain/service'; export const extrisicErrorsFilter = ({event}) => { - return dockService.dock.api.events.system.ExtrinsicFailed.is(event); + return blockchainService.dock.api.events.system.ExtrinsicFailed.is(event); }; export const mapEventToErrorMessage = ({event}) => { @@ -16,7 +16,7 @@ export const mapEventToErrorMessage = ({event}) => { if (error.isModule) { // for module errors, we have the section indexed, lookup - const decoded = dockService.dock.api.registry.findMetaError(error.asModule); + const decoded = blockchainService.dock.api.registry.findMetaError(error.asModule); const {docs, method, section} = decoded; return `${section}.${method}: ${docs.join(' ')}`; diff --git a/packages/wasm/src/services/substrate/service.ts b/packages/wasm/src/services/substrate/service.ts index 1c63c1f4..7ddd500e 100644 --- a/packages/wasm/src/services/substrate/service.ts +++ b/packages/wasm/src/services/substrate/service.ts @@ -3,7 +3,7 @@ import assert from 'assert'; import BigNumber from 'bignumber.js'; import BN from 'bn.js'; import {DOCK_TOKEN_UNIT, getPlainDockAmount} from '../../core/format-utils'; -import {dockService} from '../dock/service'; +import {blockchainService} from '../blockchain/service'; import {signAndSend} from './api-utils'; import { GetAccountBalanceParams, @@ -36,13 +36,13 @@ export class SubstrateService { validation.getAccountBalance(params); console.log('ensure dock ready'); - await dockService.ensureDockReady(); + await blockchainService.ensureBlockchainReady(); console.log('ensure dock ready done'); const { data: {free}, - } = await dockService.dock.api.query.system.account(params.address); + } = await blockchainService.dock.api.query.system.account(params.address); return free.toNumber() / DOCK_TOKEN_UNIT; } @@ -58,9 +58,9 @@ export class SubstrateService { password: '', }); - dockService.dock.setAccount(account); + blockchainService.dock.setAccount(account); - const extrinsic = dockService.dock.api.tx.balances.transfer( + const extrinsic = blockchainService.dock.api.tx.balances.transfer( toAddress, amount, ); @@ -81,7 +81,7 @@ export class SubstrateService { jsonData: keyPair, password: '', }); - const {dock} = dockService; + const {dock} = blockchainService; dock.setAccount(account); diff --git a/packages/wasm/src/services/test-utils.js b/packages/wasm/src/services/test-utils.js index 77315db1..318e85c2 100644 --- a/packages/wasm/src/services/test-utils.js +++ b/packages/wasm/src/services/test-utils.js @@ -4,11 +4,11 @@ import BigNumber from 'bignumber.js'; import {DOCK_TOKEN_UNIT} from '../core/format-utils'; import {TestFixtures} from '../fixtures'; import {NetworkManager} from '../modules/network-manager'; -import {dockService, getDock, setDock} from './dock/service'; import {keyringService} from './keyring'; import {RpcService} from './rpc-service-client'; import {walletService} from './wallet'; import Keyring from '@polkadot/keyring'; +import {blockchainService, getDock, setDock} from './blockchain/service'; export async function initializeWalletService() { await cryptoWaitReady(); @@ -50,21 +50,21 @@ export async function mockDockService() { let sdkMock; if (API_MOCK_DISABLED) { - return dockService.init({ + return blockchainService.init({ address: NetworkManager.getInstance().getNetworkInfo().substrateUrl, }); } else { sdkMock = mockDockSdkConnection(); - await dockService.init({ + await blockchainService.init({ address: NetworkManager.getInstance().getNetworkInfo().substrateUrl, }); } - const _dockSdk = dockService.dock; + const _dockSdk = blockchainService.dock; - dockService.isDockReady = true; + blockchainService.isDockReady = true; - dockService.dock = { + blockchainService.dock = { api: { events: { system: { @@ -125,11 +125,11 @@ export async function mockDockService() { }; return () => { - dockService.dock = _dockSdk; + blockchainService.dock = _dockSdk; if (sdkMock) { sdkMock.clear(); } - dockService.disconnect(); + blockchainService.disconnect(); }; } diff --git a/packages/wasm/src/services/trust-registry/index.test.js b/packages/wasm/src/services/trust-registry/index.test.js index a5948923..639c0674 100644 --- a/packages/wasm/src/services/trust-registry/index.test.js +++ b/packages/wasm/src/services/trust-registry/index.test.js @@ -1,4 +1,4 @@ -import {dockService} from '../dock/service'; +import {blockchainService} from '../blockchain/service'; import {trustRegistryService as service} from './service'; import { @@ -23,7 +23,7 @@ describe('TrustRegistryService', () => { const result = await service.getTrustRegistries(params); const queryObject = - dockService.dock.trustRegistry.registriesInfo.mock.calls[0][0]; + blockchainService.dock.trustRegistry.registriesInfo.mock.calls[0][0]; expect(queryObject.issuers.AnyOf).toHaveLength(1); expect(queryObject.verifiers.AnyOf).toHaveLength(1); expect(queryObject.schemaIds.AnyOf[0]).toEqual( @@ -42,10 +42,10 @@ describe('TrustRegistryService', () => { }; const result = await service.getTrustRegistryVerifiers(params); const queryObject = - dockService.dock.trustRegistry.registrySchemasMetadata.mock.calls[0][0]; + blockchainService.dock.trustRegistry.registrySchemasMetadata.mock.calls[0][0]; expect( - dockService.dock.trustRegistry.registrySchemasMetadata.mock.calls[0][1], + blockchainService.dock.trustRegistry.registrySchemasMetadata.mock.calls[0][1], ).toEqual(trustRegistryId); expect(queryObject.issuers.AnyOf).toHaveLength(1); expect(queryObject.schemaIds[0]).toEqual( diff --git a/packages/wasm/src/services/trust-registry/service.ts b/packages/wasm/src/services/trust-registry/service.ts index ee41b1f6..c7d3ee41 100644 --- a/packages/wasm/src/services/trust-registry/service.ts +++ b/packages/wasm/src/services/trust-registry/service.ts @@ -2,7 +2,7 @@ import {serviceName} from './configs'; import {typedHexDID} from '@docknetwork/sdk/utils/did/typed-did/helpers'; import {createHash} from 'crypto'; -import {dockService} from '../dock/service'; +import {blockchainService} from '../blockchain/service'; import {validation} from './configs'; class TrustRegistryService { @@ -35,7 +35,7 @@ class TrustRegistryService { } if (issuerDID) { - const issuerDIDMethodKey = typedHexDID(dockService.dock.api, issuerDID); + const issuerDIDMethodKey = typedHexDID(blockchainService.dock.api, issuerDID); queryOptions.issuers = { AnyOf: [issuerDIDMethodKey], }; @@ -43,7 +43,7 @@ class TrustRegistryService { if (verifierDID) { const verifierDIDMethodKey = typedHexDID( - dockService.dock.api, + blockchainService.dock.api, verifierDID, ); queryOptions.verifiers = { @@ -51,7 +51,7 @@ class TrustRegistryService { }; } - const registryInfo = await dockService.dock.trustRegistry?.registriesInfo( + const registryInfo = await blockchainService.dock.trustRegistry?.registriesInfo( queryOptions, ); @@ -65,11 +65,11 @@ class TrustRegistryService { const schemaIdHex = '0x' + hashedId; const issuerDIDMethodKey = issuerDID - ? typedHexDID(dockService.dock.api, issuerDID) + ? typedHexDID(blockchainService.dock.api, issuerDID) : null; const metadata = - await dockService.dock.trustRegistry.registrySchemasMetadata( + await blockchainService.dock.trustRegistry.registrySchemasMetadata( { schemaIds: [schemaIdHex], ...(issuerDIDMethodKey && {