Skip to content

Commit

Permalink
cheqd migration
Browse files Browse the repository at this point in the history
  • Loading branch information
maycon-mello committed Nov 28, 2024
1 parent 6996f08 commit 29622a4
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 118 deletions.
4 changes: 2 additions & 2 deletions examples/verify-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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({});
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/verification-flow/bbs-plus-expired.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down
26 changes: 13 additions & 13 deletions packages/cli/src/commands/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,50 +18,50 @@ 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
.command('getEcosystemFromDID')
.option('-d, --did <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};
4 changes: 2 additions & 2 deletions packages/core/src/credential-provider.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -259,7 +259,7 @@ async function syncCredentialStatus({
}

if (!isApiConnected) {
await dockService.ensureDockReady();
await blockchainService.ensureBlockchainReady();
isApiConnected = true;
}

Expand Down
30 changes: 15 additions & 15 deletions packages/core/src/wallet-wasm.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -7,33 +7,33 @@ 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);
}

/**
* Update existing substrate network connection
* 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<void> {
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;

Expand All @@ -53,7 +53,7 @@ export async function setSubstrateNetwork(wallet: IWallet) {
ss58Format: networkConfigs.addressPrefix,
});

dockService
blockchainService
.init({
address: networkConfigs.substrateUrl,
cheqdApiUrl: networkConfigs.cheqdApiUrl,
Expand All @@ -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));
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/relay-service/src/did/dids.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions packages/relay-service/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/relay-service/tests/didcomm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const validation = {

export type InitParams = {
address: string,
cheqdApiUrl: string,
networkId: string,
cheqdApiUrl?: string,
networkId?: string,
cheqdMnemonic?: string,
};
3 changes: 3 additions & 0 deletions packages/wasm/src/services/blockchain/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {BlockchainServiceRpc} from './service-rpc';

export const blockchainService = new BlockchainServiceRpc();
3 changes: 3 additions & 0 deletions packages/wasm/src/services/blockchain/index.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {BlockchainServiceRpc} from './service-rpc';

export const blockchainService = new BlockchainServiceRpc();
1 change: 1 addition & 0 deletions packages/wasm/src/services/blockchain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {blockchainService} from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,7 +17,7 @@ const doConnect = (

describe('DockService', () => {
it('ServiceRpc', () => {
assertRpcService(DockServiceRpc, service, validation);
assertRpcService(BlockchainServiceRpc, service, validation);
});

describe('init', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {InitParams, validation} from './configs';
/**
*
*/
export class DockServiceRpc extends RpcService {
export class BlockchainServiceRpc extends RpcService {
constructor() {
super('dock');
super('blockchain');
}

/**
Expand All @@ -19,8 +19,8 @@ export class DockServiceRpc extends RpcService {
/**
*
*/
ensureDockReady(): Promise<any> {
return this.call('ensureDockReady');
ensureBlockchainReady(): Promise<any> {
return this.call('ensureBlockchainReady');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ class AnyDIDResolver extends ResolverRouter {
/**
*
*/
export class DockService {
export class BlockchainService {
dock;
modules;
didModule;
cheqdApi;
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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
});
}
Expand All @@ -190,4 +190,4 @@ export class DockService {
}
}

export const dockService: DockService = new DockService();
export const blockchainService: BlockchainService = new BlockchainService();
Loading

0 comments on commit 29622a4

Please sign in to comment.