Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trust registry and did:key #382

Merged
merged 36 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
309e419
WIP
olegnn Oct 26, 2023
9806f6c
Trust Registry and `did:key`
olegnn Dec 12, 2023
9270646
fmt and tweaks
olegnn Dec 12, 2023
e478e60
Fix `Trust Registry` tests
olegnn Dec 12, 2023
ed64db5
Tweaks
olegnn Dec 12, 2023
f14501d
Fix import in test and remove extra argument from helper
lovesh Dec 13, 2023
159fc12
Add flag to run trust registry tests
lovesh Dec 13, 2023
1ff74ad
Fix some tests
lovesh Dec 13, 2023
a54f12c
Fix test
lovesh Dec 13, 2023
dd8fc95
Fix some schema tests and function types
lovesh Dec 13, 2023
eee7cff
Fix more schema tests
lovesh Dec 13, 2023
e96424b
Fix imports
lovesh Dec 13, 2023
219b941
Fix more tests
lovesh Dec 13, 2023
dc063a8
Tweaks
olegnn Dec 12, 2023
41fd04d
Merge branch 'trust-registry-and-did-key-impl' into trust-registry-di…
olegnn Dec 25, 2023
4805980
Tweaks
olegnn Dec 28, 2023
48e39da
Misc tweaks
olegnn Dec 29, 2023
c2e6716
Fix docs and return types
lovesh Dec 29, 2023
1daae35
Minor tweaks
olegnn Dec 30, 2023
17b538c
Merge branch 'tr' into trust-registry-did-key
olegnn Dec 30, 2023
9fa3aa4
Backward compatibility
olegnn Dec 30, 2023
93edfcc
Merge branch 'master' into trust-registry-did-key
olegnn Dec 30, 2023
a7b1467
Add note for backward compatibilty and add helper for easier DidKeypa…
lovesh Jan 2, 2024
0fd3de4
WIP: backward compatibility
olegnn Jan 5, 2024
7f7e452
Tests pass
olegnn Jan 6, 2024
af0f290
Tweaks
olegnn Jan 7, 2024
c16c4e5
Restore previous type def
olegnn Jan 7, 2024
a1f4e0a
Merge branch 'ttt' into trust-registry-did-key
olegnn Jan 7, 2024
8a2fbdd
More tweaks
olegnn Jan 8, 2024
48b6049
More corrections
olegnn Jan 8, 2024
46a6e26
Reorder assignment
olegnn Jan 8, 2024
65587cd
Attempts to fix tests
olegnn Jan 8, 2024
43243c6
More tests
olegnn Jan 8, 2024
7779131
misc small fixes
lovesh Jan 10, 2024
d5baea2
remove duplicate code
lovesh Jan 10, 2024
e8c615e
remove duplicate code
lovesh Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/integrations-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
mainnet:
runs-on: ubuntu-latest
env:
DisableTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'mainnet'
steps:
- uses: actions/checkout@v2
Expand All @@ -39,6 +40,7 @@ jobs:
testnet:
runs-on: ubuntu-latest
env:
DisableTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet'
steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 4 additions & 5 deletions example/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { u8aToString } from '@polkadot/util';

import { DockAPI } from '../src/index';
import { DockBlobIdByteSize } from '../src/modules/blob';
import { createNewDockDID } from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';
import { createNewDockDID, DidKeypair } from '../src/utils/did';

// The following can be tweaked depending on where the node is running and what
// account is to be used for sending the transaction.
Expand All @@ -20,7 +19,7 @@ async function writeAndReadBlob(dock, blobValue, dockDID, pair) {
blob: blobValue,
};

await dock.blob.new(blob, dockDID, pair, 1, { didModule: dock.did }, false);
await dock.blob.new(blob, dockDID, pair, { didModule: dock.did }, false);

console.log('Blob written, reading from chain...');

Expand All @@ -33,7 +32,7 @@ async function createAuthorDID(dock, pair) {
console.log('Creating new author DID', dockDID);

// Create an author DID to write with
const publicKey = getPublicKeyFromKeyringPair(pair);
const publicKey = pair.publicKey();
const didKey = new DidKey(publicKey, new VerificationRelationship());
await dock.did.new(dockDID, [didKey], [], false);
return dockDID;
Expand All @@ -57,7 +56,7 @@ async function main() {
const dock = await connectToNode();

// Generate keypair for DID
const pair = dock.keyring.addFromUri(randomAsHex(32));
const pair = DidKeypair.fromApi(dock);

// Generate a DID to be used as author
const dockDID = await createAuthorDID(dock, pair);
Expand Down
22 changes: 11 additions & 11 deletions example/dock-did.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import dock, {
} from '../src/index';
import {
createNewDockDID,
DidKeypair,
} from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';

// The following can be tweaked depending on where the node is running and what
// account is to be used for sending the transaction.
Expand All @@ -31,17 +31,17 @@ async function removeDID() {
console.log('Removing DID now.');

// Sign the DID removal with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

return dock.did.remove(dockDID, dockDID, pair, 1, undefined, false);
return dock.did.remove(dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addServiceEndpoint() {
console.log('Add new service endpoint now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

const spType = new ServiceEndpointType();
spType.setLinkedDomains();
Expand All @@ -50,38 +50,38 @@ async function addServiceEndpoint() {
const spId = u8aToHex(encoder.encode(spIdText));
const originsText = ['https://foo.example.com'];
const origins = originsText.map((u) => u8aToHex(encoder.encode(u)));
return dock.did.addServiceEndpoint(spId, spType, origins, dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addServiceEndpoint(spId, spType, origins, dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addController() {
console.log('Add new controller now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

const newController = createNewDockDID();

return dock.did.addControllers([newController], dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addControllers([newController], dockDID, dockDID, pair, undefined, false);
}

// This function assumes the DID has been written.
async function addKey() {
console.log('Add new key now.');

// Sign key update with this key pair as this is the current key of the DID
const pair = dock.keyring.addFromUri(firstKeySeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(firstKeySeed, null, 'sr25519'), 1);

// Update DID key to the following
const newPair = dock.keyring.addFromUri(secondKeySeed, null, 'ed25519');
const newPair = new DidKeypair(dock.keyring.addFromUri(secondKeySeed, null, 'ed25519'), 1);
// the following function will figure out the correct PublicKey type from the `type` property of `newPair`
const newPk = getPublicKeyFromKeyringPair(newPair);
const newPk = newPair.publicKey();

const vr = new VerificationRelationship();
vr.setAuthentication();
const newDidKey = new DidKey(newPk, vr);

return dock.did.addKeys([newDidKey], dockDID, dockDID, pair, 1, undefined, false);
return dock.did.addKeys([newDidKey], dockDID, dockDID, pair, undefined, false);
}

async function getDIDDoc() {
Expand Down
4 changes: 2 additions & 2 deletions example/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { randomAsHex } from '@polkadot/util-crypto';
import ethr from 'ethr-did-resolver';
import { DockAPI } from '../src/index';
import { createNewDockDID, NoDIDError } from '../src/utils/did';
import { createNewDockDID, NoDIDError, DidKeypair } from '../src/utils/did';
import {
DIDResolver, DIDKeyResolver, UniversalResolver, WILDCARD, DockDIDResolver,
} from '../src/resolver';
Expand Down Expand Up @@ -54,7 +54,7 @@ async function createDockDID() {
dock.setAccount(account);

const dockDID = createNewDockDID();
const pair = dock.keyring.addFromUri(randomAsHex(32), null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(randomAsHex(32), null, 'sr25519'), 1);
await registerNewDIDUsingPair(dock, dockDID, pair);
return dockDID;
}
Expand Down
27 changes: 13 additions & 14 deletions example/revocation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { randomAsHex } from '@polkadot/util-crypto';

import dock from '../src/index';
import { createNewDockDID } from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';
import { createNewDockDID, DidKeypair, typedHexDID } from '../src/utils/did';

import {
OneOfPolicy,
Expand All @@ -21,17 +20,17 @@ const registryId = createRandomRegistryId();
const controllerDID = createNewDockDID();
const controllerSeed = randomAsHex(32);

// Create a list of controllers
const controllers = new Set();
controllers.add(controllerDID);

// Create a registry policy
const policy = new OneOfPolicy(controllers);

// Create revoke IDs
const revokeId = randomAsHex(32);

async function createRegistry() {
// Create a list of controllers
const controllers = new Set();

controllers.add(typedHexDID(dock.api, controllerDID));

// Create a registry policy
const policy = new OneOfPolicy(controllers);
console.log(`Creating a registry with owner DID (${controllerDID}) with policy type:`, policy.constructor.name);
await dock.revocation.newRegistry(registryId, policy, false, false);
console.log('Created registry');
Expand All @@ -40,20 +39,20 @@ async function createRegistry() {
async function removeRegistry(pair) {
console.log('Removing registry...');

await dock.revocation.removeRegistryWithOneOfPolicy(registryId, controllerDID, pair, 1, { didModule: dock.did }, false);
await dock.revocation.removeRegistryWithOneOfPolicy(registryId, controllerDID, pair, { didModule: dock.did }, false);

console.log('Registry removed. All done.');
}

async function unrevoke(pair) {
console.log('Trying to undo the revocation (unrevoke) of id:', revokeId);
const extrinsic = await dock.revocation.unrevokeCredentialWithOneOfPolicy(registryId, revokeId, controllerDID, pair, 1, { didModule: dock.did }, false);
const extrinsic = await dock.revocation.unrevokeCredentialWithOneOfPolicy(registryId, revokeId, controllerDID, pair, { didModule: dock.did }, false);
await extrinsic;
}

async function revoke(pair) {
console.log('Trying to revoke id:', revokeId);
const extrinsic = await dock.revocation.revokeCredentialWithOneOfPolicy(registryId, revokeId, controllerDID, pair, 1, { didModule: dock.did }, false);
const extrinsic = await dock.revocation.revokeCredentialWithOneOfPolicy(registryId, revokeId, controllerDID, pair, { didModule: dock.did }, false);
await extrinsic;
}

Expand All @@ -65,13 +64,13 @@ async function main() {
dock.setAccount(account);

// The DID should be written before creating a registry
const pair = dock.keyring.addFromUri(controllerSeed, null, 'sr25519');
const pair = new DidKeypair(dock.keyring.addFromUri(controllerSeed, null, 'sr25519'), 1);

// Set our controller DID and associated keypair to be used for generating proof
console.log(`Creating controller DID (${controllerDID}) using sr25519 pair from seed (${controllerSeed})...`);

// The controller is same as the DID
const publicKey = getPublicKeyFromKeyringPair(pair);
const publicKey = pair.publicKey();
const didKey = new DidKey(publicKey, new VerificationRelationship());
await dock.did.new(controllerDID, [didKey], [], false);

Expand Down
11 changes: 5 additions & 6 deletions example/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { randomAsHex } from '@polkadot/util-crypto';
import Schema from '../src/modules/schema';

import { DockAPI } from '../src/index';
import { createNewDockDID } from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';
import { createNewDockDID, DidKeypair } from '../src/utils/did';
import VerifiableCredential from '../src/verifiable-credential';
import { Ed25519VerKeyName } from '../src/utils/vc/crypto/constants';
import { getKeyDoc } from '../src/utils/vc/helpers';
Expand All @@ -27,7 +26,7 @@ async function createAuthorDID(dock, pair) {
console.log('Creating new author DID', dockDID);

// Create an author DID to write with
const publicKey = getPublicKeyFromKeyringPair(pair);
const publicKey = pair.publicKey();
const didKey = new DidKey(publicKey, new VerificationRelationship());
await dock.did.new(dockDID, [didKey], [], false);
return dockDID;
Expand All @@ -47,7 +46,7 @@ async function main() {
const subjectKeySeed = randomAsHex(32);

// Generate first key with this seed. The key type is Sr25519
const pair = dock.keyring.addFromUri(keySeed, null, 'ed25519');
const pair = new DidKeypair(dock.keyring.addFromUri(keySeed, null, 'ed25519'), 1);

// Generate a DID to be used as author
const dockDID = await createAuthorDID(dock, pair);
Expand All @@ -59,7 +58,7 @@ async function main() {
Ed25519VerKeyName,
);

const subjectPair = dock.keyring.addFromUri(subjectKeySeed);
const subjectPair = new DidKeypair(dock.keyring.addFromUri(subjectKeySeed), 1);
const subjectDID = createNewDockDID();
await registerNewDIDUsingPair(dock, subjectDID, subjectPair);

Expand Down Expand Up @@ -88,7 +87,7 @@ async function main() {
console.log('The schema is:', JSON.stringify(schema.toJSON(), null, 2));
console.log('Writing schema to the chain with blob id of', schema.id, '...');

await schema.writeToChain(dock, dockDID, pair, 1, undefined, false);
await schema.writeToChain(dock, dockDID, pair, undefined, false);

console.log(`Schema written, reading from chain (${schema.id})...`);

Expand Down
8 changes: 4 additions & 4 deletions example/vcdm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { randomAsHex } from '@polkadot/util-crypto';
import dock from '../src/index';
import VerifiableCredential from '../src/verifiable-credential';
import VerifiablePresentation from '../src/verifiable-presentation';
import { createNewDockDID } from '../src/utils/did';
import { createNewDockDID, DidKeypair, typedHexDID } from '../src/utils/did';
import { registerNewDIDUsingPair } from '../tests/integration/helpers';
import { createRandomRegistryId, OneOfPolicy, buildDockCredentialStatus } from '../src/utils/revocation';
import { FullNodeEndpoint, TestAccountURI } from '../tests/test-constants';
Expand Down Expand Up @@ -44,17 +44,17 @@ async function setup() {

// Register issuer DID
console.log('Registering issuer DID...');
const pair = dock.keyring.addFromUri(issuerSeed, null, 'ed25519');
const pair = new DidKeypair(dock.keyring.addFromUri(issuerSeed, null, 'ed25519'), 1);
await registerNewDIDUsingPair(dock, issuerDID, pair);

// Register holder DID
console.log('Registering holder DID...');
const pair1 = dock.keyring.addFromUri(holderSeed, null, 'ed25519');
const pair1 = new DidKeypair(dock.keyring.addFromUri(holderSeed, null, 'ed25519'), 1);
await registerNewDIDUsingPair(dock, holderDID, pair1);

// Create a new policy
const policy = new OneOfPolicy();
policy.addOwner(issuerDID);
policy.addOwner(typedHexDID(dock.api, issuerDID));

// Add a new revocation registry with above policy
console.log('Creating registry...');
Expand Down
23 changes: 12 additions & 11 deletions scripts/hit_1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomAsHex } from '@polkadot/util-crypto';
import dock, { DockAPI } from '../src/index';
import {
createNewDockDID,
createNewDockDID, DidKeypair,
} from '../src/utils/did';
import { getPublicKeyFromKeyringPair } from '../src/utils/misc';
import { sendBatch } from './helpers';
Expand Down Expand Up @@ -47,7 +47,7 @@ async function sendOnChainDIDTxns(count, waitForFinalization = true) {
const didKey = new DidKey(publicKey, new VerificationRelationship());
const tx = dock.did.createNewOnchainTx(did, [didKey], []);
txs.push(tx);
didPairs.push([did, pair]);
didPairs.push([did, new DidKeypair(pair, 1)]);
}

await sendBatch(dock, txs, account.address, waitForFinalization);
Expand Down Expand Up @@ -77,7 +77,7 @@ async function sendAddKeyTxns(count, didPairs) {
const newPair = dock.keyring.addFromUri(seed, null, 'sr25519');
const publicKey = getPublicKeyFromKeyringPair(newPair);
const didKey = new DidKey(publicKey, new VerificationRelationship());
const tx = await dock.did.createAddKeysTx([didKey], did, did, currentPair, 1);
const tx = await dock.did.createAddKeysTx([didKey], did, did, currentPair);
txs.push(tx);
j++;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ async function sendAddControllerTxns(count, didPairs) {
while (txs.length < count) {
const did = didPairs[j][0];
const currentPair = didPairs[j][1];
const tx = await dock.did.createAddControllersTx([createNewDockDID()], did, did, currentPair, 1);
const tx = await dock.did.createAddControllersTx([createNewDockDID()], did, did, currentPair);
txs.push(tx);
j++;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ async function sendRemoveTxns(count, didPairs, waitForFinalization = true) {
while (txs.length < count) {
const did = didPairs[j][0];
const currentPair = didPairs[j][1];
const tx = await dock.did.createRemoveTx(did, did, currentPair, 1);
const tx = await dock.did.createRemoveTx(did, did, currentPair);
txs.push(tx);
j++;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ async function sendBlobTxns(count, didPairs) {
id: blobId,
blob: randomAsHex(995),
};
const tx = await dock.blob.createNewTx(blob, did, pair, 1, { didModule: dock.did });
const tx = await dock.blob.createNewTx(blob, did, pair, { didModule: dock.did });
txs.push(tx);
blobIds.push(blobId);
j++;
Expand Down Expand Up @@ -207,15 +207,16 @@ async function sendAnchorTxns(count) {
}

async function runOnce() {
let didPairs = await sendOnChainDIDTxns(1950);
const count = 1000;
let didPairs = await sendOnChainDIDTxns(count);
console.log('');
didPairs = await sendAddKeyTxns(1950, didPairs);
didPairs = await sendAddKeyTxns(count, didPairs);
console.log('');
await sendAddControllerTxns(1950, didPairs);
await sendAddControllerTxns(count, didPairs);
console.log('');
await sendBlobTxns(1500, didPairs);
await sendBlobTxns(800, didPairs);
console.log('');
await sendRemoveTxns(1950, didPairs);
await sendRemoveTxns(count, didPairs);
}

async function runInLoop(limit) {
Expand Down
Loading
Loading