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 5 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: 1 addition & 1 deletion example/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 Down
8 changes: 4 additions & 4 deletions example/dock-did.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function removeDID() {
// 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');

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.
Expand All @@ -50,7 +50,7 @@ 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.
Expand All @@ -62,7 +62,7 @@ async function addController() {

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.
Expand All @@ -81,7 +81,7 @@ async function addKey() {
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
6 changes: 3 additions & 3 deletions example/revocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,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 Down
2 changes: 1 addition & 1 deletion example/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 scripts/hit_1.js
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions scripts/master_voting/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { u8aToHex } from '@polkadot/util';
import { connect, keypair } from '../helpers';
import { getHexIdentifierFromDID } from '../../src/utils/did';
import { typedHexDID } from '../../src/utils/did';
import { getStateChange } from '../../src/utils/misc';

require('dotenv').config();
Expand Down Expand Up @@ -45,7 +45,7 @@ async function main() {

const round_no = parseIntChecked(process.argv[2]);

const did = getHexIdentifierFromDID(did);
const did = typedHexDID(dock.api, did);

const proposal_filename = process.argv[3];
const proposal_unparsed = await fsp.readFile(proposal_filename);
Expand Down Expand Up @@ -86,7 +86,7 @@ async function main() {
console.log('');

const encodedProposal = [...nc.api.createType('Call', proposal).toU8a()];
const nonce = await nc.didModule.getNextNonceForDID(did);
const nonce = await nc.didModule.getNextNonceForDid(did);
const vote = { nonce, proposal: encodedProposal, round_no: actual_round_no };
const encodedStateChange = getStateChange(nc.api, 'MasterVote', vote);

Expand Down
66 changes: 33 additions & 33 deletions scripts/txn-pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ async function dids() {
const [, , dk1] = getDidPair();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding DID key with all verification relationships');
await dock.did.addKeys([dk1], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk1], did, did, pair, undefined, false);
});

// Add DID key with only 1 verification relationship
const [, , dk2] = getDidPair();
dk2.verRels.setAuthentication();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding DID key with only 1 verification relationship');
await dock.did.addKeys([dk2], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk2], did, did, pair, undefined, false);
});

// Add DID key with only 2 verification relationships
Expand All @@ -76,7 +76,7 @@ async function dids() {
dk3.verRels.setAssertion();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding DID key with only 2 verification relationships');
await dock.did.addKeys([dk3], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk3], did, did, pair, undefined, false);
});

// Add DID key with 3 verification relationships
Expand All @@ -86,7 +86,7 @@ async function dids() {
dk4.verRels.setCapabilityInvocation();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding DID key with 3 verification relationships');
await dock.did.addKeys([dk4], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk4], did, did, pair, undefined, false);
});

// Add 2 DID keys with only 1 verification relationship
Expand All @@ -96,7 +96,7 @@ async function dids() {
dk6.verRels.setCapabilityInvocation();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 2 DID keys with only 1 verification relationship');
await dock.did.addKeys([dk5, dk6], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk5, dk6], did, did, pair, undefined, false);
});

// Add 3 DID keys with only 1 verification relationship
Expand All @@ -108,20 +108,20 @@ async function dids() {
dk9.verRels.setAssertion();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 3 DID keys with only 1 verification relationship');
await dock.did.addKeys([dk7, dk8, dk9], did, did, pair, 1, undefined, false);
await dock.did.addKeys([dk7, dk8, dk9], did, did, pair, undefined, false);
});

const newControllers = [createNewDockDID(), createNewDockDID(), createNewDockDID()];
// Add 1 controller
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 1 controller');
await dock.did.addControllers([newControllers[0]], did, did, pair, 1, undefined, false);
await dock.did.addControllers([newControllers[0]], did, did, pair, undefined, false);
});

// Add 2 controllers
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 2 controllers');
await dock.did.addControllers([newControllers[1], newControllers[2]], did, did, pair, 1, undefined, false);
await dock.did.addControllers([newControllers[1], newControllers[2]], did, did, pair, undefined, false);
});

const spType = new ServiceEndpointType();
Expand All @@ -133,13 +133,13 @@ async function dids() {
// Add 1 service endpoint with 1 origin
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 1 service endpoint with 1 origin');
await dock.did.addServiceEndpoint(spId1, spType, origins1, did, did, pair, 1, undefined, false);
await dock.did.addServiceEndpoint(spId1, spType, origins1, did, did, pair, undefined, false);
});

// Add 1 service endpoint with 2 origins
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding 1 service endpoint with 2 origins');
await dock.did.addServiceEndpoint(spId2, spType, origins2, did, did, pair, 1, undefined, false);
await dock.did.addServiceEndpoint(spId2, spType, origins2, did, did, pair, undefined, false);
});

// Adding a new DID which doesn't control itself but controlled by one other controller
Expand Down Expand Up @@ -167,43 +167,43 @@ async function dids() {
const [, , dk__] = getDidPair();
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding DID key with all verification relationships to a DID that doesnt control itself');
await dock.did.addKeys([dk__], did1, did, pair, 1, undefined, false);
await dock.did.addKeys([dk__], did1, did, pair, undefined, false);
});

// Removing 1 key
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing 1 key');
await dock.did.removeKeys([2], did, did, pair, 1, undefined, false);
await dock.did.removeKeys([2], did, did, pair, undefined, false);
});

// Removing 2 keys
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing 2 keys');
await dock.did.removeKeys([3, 4], did, did, pair, 1, undefined, false);
await dock.did.removeKeys([3, 4], did, did, pair, undefined, false);
});

// Removing 1 controller
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing 1 controller');
await dock.did.removeControllers([newControllers[0]], did, did, pair, 1, undefined, false);
await dock.did.removeControllers([newControllers[0]], did, did, pair, undefined, false);
});

// Removing 2 controllers
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing 2 controllers');
await dock.did.removeControllers([newControllers[1], newControllers[2]], did, did, pair, 1, undefined, false);
await dock.did.removeControllers([newControllers[1], newControllers[2]], did, did, pair, undefined, false);
});

// Removing 1 service endpoint
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing service endpoint');
await dock.did.removeServiceEndpoint(spId1, did, did, pair, 1, undefined, false);
await dock.did.removeServiceEndpoint(spId1, did, did, pair, undefined, false);
});

// Remove DID
await printFeePaid(dock.api, account.address, async () => {
console.info('Removing DID');
await dock.did.remove(did, did, pair, 1, undefined, false);
await dock.did.remove(did, did, pair, undefined, false);
});
}

Expand Down Expand Up @@ -232,16 +232,16 @@ async function revocation() {
revokeIds.add(randomAsHex(32));
}

const [update, sig, nonce] = await dock.revocation.createSignedRevoke(registryId, revokeIds, did, pair, 1, { didModule: dock.did });
const revTx = dock.revocation.createRevokeTx(update, [[sig, nonce]]);
const [update, sig, nonce] = await dock.revocation.createSignedRevoke(registryId, revokeIds, did, pair, { didModule: dock.did });
const revTx = dock.revocation.createRevokeTx(update, [[nonce, sig]]);
console.info(`Payment info of ${count} revocation is ${(await revTx.paymentInfo(account.address))}`);
await printFeePaid(dock.api, account.address, async () => {
await dock.signAndSend(revTx, false);
});
}

const [update, sig, nonce] = await dock.revocation.createSignedRemove(registryId, did, pair, 1, { didModule: dock.did });
const revTx = dock.revocation.createRemoveRegistryTx(update, [[sig, nonce]]);
const [update, sig, nonce] = await dock.revocation.createSignedRemove(registryId, did, pair, { didModule: dock.did });
const revTx = dock.revocation.createRemoveRegistryTx(update, [[nonce, sig]]);
console.info(`Payment info of removing registry is ${(await revTx.paymentInfo(account.address))}`);

await printFeePaid(dock.api, account.address, async () => {
Expand Down Expand Up @@ -274,7 +274,7 @@ async function blobs() {
};
await printFeePaid(dock.api, account.address, async () => {
console.info('Blob write');
await dock.blob.new(blob, did, pair, 1, { didModule: dock.did }, false);
await dock.blob.new(blob, did, pair, { didModule: dock.did }, false);
});
}

Expand All @@ -295,7 +295,7 @@ async function bbsPlus() {
const params = BBSPlusModule.prepareAddParameters(bytes, undefined, label);
await printFeePaid(dock.api, account.address, async () => {
console.info(`Add BBS+ params with ${attributeCount} attributes`);
await dock.bbsPlusModule.addParams(params, did, pair, 1, { didModule: dock.did }, false);
await dock.bbsPlusModule.addParams(params, did, pair, { didModule: dock.did }, false);
});
}

Expand All @@ -304,19 +304,19 @@ async function bbsPlus() {
const pk = BBSPlusModule.prepareAddPublicKey(u8aToHex(kp.publicKey.bytes), undefined, [did, 1]);
await printFeePaid(dock.api, account.address, async () => {
console.info('Add a BBS+ key');
await dock.bbsPlusModule.addPublicKey(pk, did, did, pair, 1, { didModule: dock.did }, false);
await dock.bbsPlusModule.addPublicKey(pk, did, did, pair, { didModule: dock.did }, false);
});

// Remove public key
await printFeePaid(dock.api, account.address, async () => {
console.info('Remove BBS+ key');
await dock.bbsPlusModule.removePublicKey(2, did, did, pair, 1, { didModule: dock.did }, false);
await dock.bbsPlusModule.removePublicKey(2, did, did, pair, { didModule: dock.did }, false);
});

// Remove params
await printFeePaid(dock.api, account.address, async () => {
console.info('Remove BBS+ params');
await dock.bbsPlusModule.removeParams(1, did, pair, 1, { didModule: dock.did }, false);
await dock.bbsPlusModule.removeParams(1, did, pair, { didModule: dock.did }, false);
});
}

Expand All @@ -334,30 +334,30 @@ async function accumulator() {
const params = AccumulatorModule.prepareAddParameters(bytes, undefined, label);
await printFeePaid(dock.api, account.address, async () => {
console.info('Accumulator params write');
await dock.accumulatorModule.addParams(params, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.addParams(params, did, pair, { didModule: dock.did }, false);
});

const kp = Accumulator.generateKeypair(new AccumulatorParams(hexToU8a(params.bytes)));

const pk = AccumulatorModule.prepareAddPublicKey(u8aToHex(kp.publicKey.bytes), undefined, [did, 1]);
await printFeePaid(dock.api, account.address, async () => {
console.info('Accumulator key write');
await dock.accumulatorModule.addPublicKey(pk, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.addPublicKey(pk, did, pair, { didModule: dock.did }, false);
});

const accumulatorPos = PositiveAccumulator.initialize(new AccumulatorParams(hexToU8a(params.bytes)), kp.secretKey);
const accumulatorIdPos = randomAsHex(32);
const accumulatedPos = u8aToHex(accumulatorPos.accumulated);
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding a positive accumulator');
await dock.accumulatorModule.addPositiveAccumulator(accumulatorIdPos, accumulatedPos, [did, 1], did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.addPositiveAccumulator(accumulatorIdPos, accumulatedPos, [did, 1], did, pair, { didModule: dock.did }, false);
});

const accumulatorIdUni = randomAsHex(32);
const accumulatedUni = u8aToHex(accumulatorPos.accumulated);
await printFeePaid(dock.api, account.address, async () => {
console.info('Adding a universal accumulator');
await dock.accumulatorModule.addUniversalAccumulator(accumulatorIdUni, accumulatedUni, [did, 1], 10000, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.addUniversalAccumulator(accumulatorIdUni, accumulatedUni, [did, 1], 10000, did, pair, { didModule: dock.did }, false);
});

const start = 10;
Expand All @@ -372,20 +372,20 @@ async function accumulator() {
let witUpd = u8aToHex(WitnessUpdatePublicInfo.new(hexToU8a(accumulated), members, [], kp.secretKey).value);
await printFeePaid(dock.api, account.address, async () => {
console.info(`Updating a positive accumulator with ${members.length} additions`);
await dock.accumulatorModule.updateAccumulator(accumulatorIdPos, accumulated, { additions: members.map((m) => u8aToHex(m)), witnessUpdateInfo: witUpd }, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.updateAccumulator(accumulatorIdPos, accumulated, { additions: members.map((m) => u8aToHex(m)), witnessUpdateInfo: witUpd }, did, pair, { didModule: dock.did }, false);
});

witUpd = u8aToHex(WitnessUpdatePublicInfo.new(hexToU8a(accumulated), [], members, kp.secretKey).value);

await printFeePaid(dock.api, account.address, async () => {
console.info(`Updating a positive accumulator with ${members.length} removals`);
await dock.accumulatorModule.updateAccumulator(accumulatorIdPos, accumulated, { removals: members.map((m) => u8aToHex(m)), witnessUpdateInfo: witUpd }, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.updateAccumulator(accumulatorIdPos, accumulated, { removals: members.map((m) => u8aToHex(m)), witnessUpdateInfo: witUpd }, did, pair, { didModule: dock.did }, false);
});
}

await printFeePaid(dock.api, account.address, async () => {
console.info('Removing a positive accumulator');
await dock.accumulatorModule.removeAccumulator(accumulatorIdPos, did, pair, 1, { didModule: dock.did }, false);
await dock.accumulatorModule.removeAccumulator(accumulatorIdPos, did, pair, { didModule: dock.did }, false);
});
}

Expand Down
Loading
Loading