Skip to content

Commit

Permalink
upgrade sdk + remove old sdk references
Browse files Browse the repository at this point in the history
  • Loading branch information
maycon-mello committed Jan 22, 2025
1 parent 84e3196 commit e230899
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 475 deletions.
3 changes: 1 addition & 2 deletions integration-tests/verification-flow/bbs-plus-expired.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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 {verifyPresentation} from '@docknetwork/credential-sdk/vc';
import assert from 'assert';
import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index';
import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';

const testAPIURL = process.env.TESTING_API_URL || null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
getWallet,
} from '../helpers/wallet-helpers';
import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/verification-controller';
import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations';
import axios from 'axios';
import {ProofTemplateIds, createProofRequest} from '../helpers/certs-helpers';
import { bbsPlusRevocationCredential, credentialWithUpdatedWitness } from './bbs-plus-revocation-credentials';

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/verification-flow/bbs-plus-valid.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,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 {verifyPresentation} from '@docknetwork/credential-sdk/vc';
import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';

const credential = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,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 {verifyPresentation} from '@docknetwork/credential-sdk/vc';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';
import {autoLoanProofRequest} from './proof-requests';

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
"@babel/preset-typescript": "^7.22.5",
"@cosmjs/proto-signing": "^0.32.4",
"@digitalbazaar/x25519-key-agreement-key-2020": "2.1.0",
"@docknetwork/cheqd-blockchain-api": "^0.20.0",
"@docknetwork/cheqd-blockchain-modules": "^0.17.0",
"@docknetwork/credential-sdk": "0.26.0",
"@docknetwork/dock-blockchain-api": "0.11.0",
"@docknetwork/dock-blockchain-modules": "0.15.0",
"@docknetwork/cheqd-blockchain-api": "^0.21.0",
"@docknetwork/cheqd-blockchain-modules": "^0.18.0",
"@docknetwork/credential-sdk": "0.27.0",
"@docknetwork/dock-blockchain-api": "0.12.0",
"@docknetwork/dock-blockchain-modules": "0.16.0",
"@inquirer/checkbox": "^1.3.8",
"@inquirer/input": "^1.2.8",
"@inquirer/prompts": "^3.0.3",
Expand Down
255 changes: 0 additions & 255 deletions packages/cli/src/bbs-revocation.ts

This file was deleted.

25 changes: 0 additions & 25 deletions packages/cli/src/commands/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Command} from 'commander';
import {typedHexDID} from '@docknetwork/sdk/utils/did/typed-did/helpers';
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';
Expand Down Expand Up @@ -40,28 +39,4 @@ ecosystemCommands
await blockchainService.disconnect();
});

ecosystemCommands
.command('getEcosystemFromDID')
.option('-d, --did <did>', 'DID')
.description('Get ecosystem from issuer DID')
.action(async ({did}) => {
await blockchainService.init({
address: 'wss://knox-1.dock.io',
});

await blockchainService.waitBlockchainReady();
await blockchainService.ensureBlockchainReady();

const issuerDIDMethodKey = typedHexDID(
blockchainService.dock.api,
did,
);
const registryInfo = await blockchainService.dock.trustRegistry?.registriesInfo({
Issuer: issuerDIDMethodKey,
});
console.log(registryInfo);

await blockchainService.disconnect();
});

export {ecosystemCommands};
1 change: 0 additions & 1 deletion packages/relay-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"dependencies": {
"uuid": "^9.0.0",
"@docknetwork/minimal-cipher": "^5.2.1",
"@docknetwork/sdk": "8.6.0",
"@docknetwork/wallet-sdk-wasm": "0.4.19"
},
"devDependencies": {
Expand Down
18 changes: 0 additions & 18 deletions packages/relay-service/src/did/dids.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/relay-service/src/didcomm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {v1 as uuidv1} from 'uuid';
import base64url from 'base64url';
import * as bs58 from 'base58-universal';

import {resolveDID} from './did/dids';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service';

export const DIDCOMM_TYPE_BASIC =
'https://didcomm.org/basicmessage/1.0/message';
Expand Down Expand Up @@ -34,7 +34,7 @@ function potentialToArray(a) {
}

export async function getKeydocFromDID(didUrl) {
const didDocument = await resolveDID(didUrl);
const didDocument = await blockchainService.resolver.resolve(didUrl);
const possibleKeys = [
...potentialToArray(didDocument.verificationMethod),
...potentialToArray(didDocument.keyAgreement),
Expand Down Expand Up @@ -201,7 +201,7 @@ export async function getAgreementKeydocFromDID(did) {

// Resolve actual DID document and get key agreement keys
const isDIDUrl = did.indexOf('#') !== -1;
const didDocument = await resolveDID(did);
const didDocument = await blockchainService.resolver.resolve(did);
const keyAgreements = didDocument.keyAgreement
? Array.isArray(didDocument.keyAgreement)
? didDocument.keyAgreement
Expand Down
6 changes: 4 additions & 2 deletions packages/relay-service/src/payloads.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import VerifiableCredential from '@docknetwork/sdk/verifiable-credential';
import {
VerifiableCredential,
getSuiteFromKeyDoc,
} from '@docknetwork/credential-sdk/vc';
import {cryptoWaitReady} from '@polkadot/util-crypto';
import {getSuiteFromKeyDoc} from '@docknetwork/sdk/utils/vc/helpers';
import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
import assert from 'assert';
import base64url from 'base64url';
Expand Down
13 changes: 3 additions & 10 deletions packages/relay-service/tests/didcomm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import {
} from '../lib/didcomm';
import {ALICE_KEY_PAIR_DOC, BOB_KEY_PAIR_DOC} from './mock-data';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service';
import {WildcardMultiResolver} from '@docknetwork/sdk/resolver';
import {ResolverRouter} from '@docknetwork/credential-sdk/resolver';

const didList = [ALICE_KEY_PAIR_DOC, BOB_KEY_PAIR_DOC];

class WalletSDKResolver extends WildcardMultiResolver {
static PREFIX = WildcardMultiResolver.PREFIX;
static METHOD = WildcardMultiResolver.METHOD;

class WalletSDKResolver extends ResolverRouter {
async resolve(did) {
const trimmedDID = did.split('#')[0];
const document = didList.find(
Expand All @@ -28,11 +25,7 @@ class WalletSDKResolver extends WildcardMultiResolver {
}
}

const mockDIDResolver = new WalletSDKResolver([
// new DockResolver(dock),
// new DIDKeyResolver(),
// new UniversalResolver(universalResolverUrl),
]);
const mockDIDResolver = new WalletSDKResolver([]);

blockchainService.createDIDResolver = () => mockDIDResolver;
blockchainService.resolver = mockDIDResolver;
Expand Down
3 changes: 1 addition & 2 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@polkadot/types": "5.6.1",
"@polkadot/types-known": "5.6.1",
"@polkadot/util": "7.9.2",
"@polkadot/rpc-core": "5.6.1",
"@docknetwork/sdk": "1.2.3"
"@polkadot/rpc-core": "5.6.1"
},
"devDependencies": {
"@polkadot/types": "5.6.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"resolutions": {
"@polkadot/wasm-crypto": "6.3.1",
"@polkadot/rpc-core": "9.7.1",
"@docknetwork/sdk": "8.6.0",
"@polkadot/api": "9.7.1",
"@polkadot/keyring": "10.1.11",
"@polkadot/rpc-provider": "9.7.1",
Expand All @@ -36,7 +35,8 @@
"@polkadot/util": "10.1.11",
"@polkadot/util-crypto": "10.1.11",
"@polkadot/wasm-crypto": "6.3.1",
"@docknetwork/sdk": "8.6.0",
"@docknetwork/credential-sdk": "0.27.0",
"@docknetwork/dock-blockchain-modules": "0.16.0",
"axios": "^0.25.0",
"babel-node": "^0.0.1-security",
"bignumber.js": "^9.0.1",
Expand Down
17 changes: 14 additions & 3 deletions packages/wasm/src/core/polkadot-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {
sr25519PairFromSeed,
secp256k1PairFromSeed,
} from '@polkadot/util-crypto';

import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
import {decodePair} from '@polkadot/keyring/pair/decode';
import {getKeyPairType} from '@docknetwork/sdk/utils/misc';

import * as bs58 from 'base58-universal';

import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
Expand All @@ -20,6 +18,19 @@ const polkadotTypesToKeys = {
ecdsa: 'EcdsaSecp256k1VerificationKey2019',
};

export function getKeyPairType(key) {
const keyType = key.type || key.constructor.VerKeyType;
if (keyType) {
return keyType;
}

if (key instanceof Ed25519Keypair) {
return 'Ed25519VerificationKey2018';
}

throw new Error(`Unknown key type for ${key.constructor.name}`);
}

const TYPE_FROM_SEED = {
ecdsa: secp256k1PairFromSeed,
secp256k1: secp256k1PairFromSeed,
Expand Down
11 changes: 5 additions & 6 deletions packages/wasm/src/services/credential/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {assertRpcService, getPromiseError} from '../test-utils';
import {credentialService as service} from './service';
import {validation} from './config';
import * as credentialsUtils from '@docknetwork/sdk/utils/vc/credentials';
import * as credentialUtils from '@docknetwork/credential-sdk/vc';
import {CredentialServiceRPC} from './service-rpc';
import {getTestWallet} from '../../test/setup-test-state';
import BbsPlusPresentation from '@docknetwork/sdk/presentation';

describe('Credential Service', () => {
beforeAll(async () => {
Expand All @@ -19,7 +18,7 @@ describe('Credential Service', () => {
});
it('expect to verify credential', async () => {
jest
.spyOn(credentialsUtils, 'verifyCredential')
.spyOn(credentialUtils, 'verifyCredential')
.mockImplementationOnce(async () => ({verified: true}));
const credential = {
'@context': [
Expand Down Expand Up @@ -71,7 +70,7 @@ describe('Credential Service', () => {
},
};
await service.verifyCredential({credential});
expect(credentialsUtils.verifyCredential).toBeCalled();
expect(credentialUtils.verifyCredential).toBeCalled();
});
it('should create a vc', async () => {
const subject = {
Expand Down Expand Up @@ -296,7 +295,7 @@ describe('Credential Service', () => {
credentials,
});

const bbsPresentation = new BbsPlusPresentation();
const bbsPresentation = new credentialUtils.Presentation();
expect(bbsPresentation.addCredentialToPresent).toBeCalledWith(
credential,
expect.any(Object),
Expand Down Expand Up @@ -366,7 +365,7 @@ describe('Credential Service', () => {
credentials,
});

const bbsPresentation = new BbsPlusPresentation();
const bbsPresentation = new credentialUtils.Presentation();
expect(bbsPresentation.addCredentialToPresent).toBeCalledWith(
credential,
expect.any(Object),
Expand Down
13 changes: 7 additions & 6 deletions packages/wasm/src/services/credential/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
} from '@docknetwork/crypto-wasm-ts';
import {OpenID4VCIClientV1_0_13} from '@sphereon/oid4vci-client';
import {Alg} from '@sphereon/oid4vci-common';
import {getDockRevIdFromCredential} from '@docknetwork/sdk/utils/revocation';
import VerifiableCredential from '@docknetwork/sdk/verifiable-credential';
import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
import {getSuiteFromKeyDoc} from '@docknetwork/sdk/utils/vc/helpers';
import VerifiablePresentation from '@docknetwork/sdk/verifiable-presentation';
import Presentation from '@docknetwork/sdk/presentation';
import {verifyCredential} from '@docknetwork/sdk/utils/vc/credentials';
import {
VerifiablePresentation,
Presentation,
verifyCredential,
VerifiableCredential,
getSuiteFromKeyDoc,
} from '@docknetwork/credential-sdk/vc';
import {PEX} from '@sphereon/pex';
import {keyDocToKeypair} from './utils';
import {blockchainService, getDock} from '../blockchain/service';
Expand Down
16 changes: 3 additions & 13 deletions packages/wasm/src/services/credential/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import * as bs58 from 'base58-universal';
import {generateEcdsaSecp256k1Keypair} from '@docknetwork/sdk/utils/misc';
import {randomAsHex} from '@polkadot/util-crypto';
import {u8aToHex} from '@polkadot/util';
import Bls12381G2KeyPairDock2022 from '@docknetwork/sdk/utils/vc/crypto/Bls12381G2KeyPairDock2022';
import {Bls12381G2KeyPairDock2022} from '@docknetwork/credential-sdk/vc/crypto';
import {getKeyring} from '../keyring/service';
function createSecp256k1Keypair(privateKeyHex) {
const pk = privateKeyHex || randomAsHex(32);
const kp = generateEcdsaSecp256k1Keypair(pk);
kp.pk = pk;
return kp;
}

const docToKeyMap = {
Sr25519VerificationKey2020: 'sr25519',
Ed25519VerificationKey2018: 'ed25519',
Expand All @@ -26,9 +18,7 @@ export function keyDocToKeypair(keyDoc, dock) {
const privateKeyEncoded = privateKeyBase58 || privateKeyMultibase.substr(1);
const privateKeyBytes = bs58.decode(privateKeyEncoded);

if (type === 'EcdsaSecp256k1VerificationKey2019') {
return createSecp256k1Keypair(u8aToHex(privateKeyBytes));
} else if (type === 'Bls12381G2VerificationKeyDock2022') {
if (type === 'Bls12381G2VerificationKeyDock2022') {
return new Bls12381G2KeyPairDock2022(keyDoc);
} else {
const publicKeyEncoded = publicKeyBase58 || publicKeyMultibase.substr(1);
Expand Down
8 changes: 7 additions & 1 deletion packages/wasm/src/services/trust-registry/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// @ts-nocheck
import {serviceName} from './configs';
import {typedHexDID} from '@docknetwork/sdk/utils/did/typed-did/helpers';
import {createHash} from 'crypto';
import {blockchainService} from '../blockchain/service';
import {validation} from './configs';


// TODO: Implement this function when the Trust Registry support is added to the SDK
function typedHexDID(resolver, issuerDID) {
return issuerDID;
}

// Trust Registry Service is not supported in the current version of the SDK
class TrustRegistryService {
constructor() {
this.name = serviceName;
Expand Down
13 changes: 1 addition & 12 deletions scripts/integration-test-teardown.js
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import dock from '@docknetwork/sdk';

module.exports = async () => {
if (dock.isConnected) {
try {
console.log('Disconnecting from Dock node');
await dock.disconnect();
} catch (err) {
console.error('Error disconnecting from Dock node', err);
}
}
};
module.exports = async () => {};
Loading

0 comments on commit e230899

Please sign in to comment.