Skip to content

Commit

Permalink
[dids] implement method that generates the necessary key pairs used f…
Browse files Browse the repository at this point in the history
…or authz, attestation, and encryption when interfacing with DWNs
  • Loading branch information
mistermoe authored and frankhinek committed May 19, 2023
1 parent c0f5aab commit ea33290
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
46 changes: 46 additions & 0 deletions packages/dids/src/did-ion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,50 @@ export class DidIonApi implements DidMethodResolver, DidMethodCreator {
const didResolutionResult = await response.json();
return didResolutionResult;
}

/**
* generates three key pairs used for attestation, authorization and encryption purposes
* when interfacing with DWNs. the ids of these keys are referenced in the service object
* that includes the dwnUrls provided.
*/
async generateDwnConfiguration(dwnUrls: string[]): Promise<DidIonCreateOptions> {
return DidIonApi.generateDwnConfiguration(dwnUrls);
}

/**
* generates three key pairs used for attestation, authorization and encryption purposes
* when interfacing with DWNs. the ids of these keys are referenced in the service object
* that includes the dwnUrls provided.
*/
static async generateDwnConfiguration(dwnUrls: string[]): Promise<DidIonCreateOptions> {
const keys = [{
id : 'attest',
type : 'JsonWebKey2020',
keyPair : await generateKeyPair('secp256k1'),
purposes : ['authentication'],
}, {
id : 'authz',
type : 'JsonWebKey2020',
keyPair : await generateKeyPair('secp256k1'),
purposes : ['authentication'],
}, {
id : 'encr',
type : 'JsonWebKey2020',
keyPair : await generateKeyPair('secp256k1'),
purposes : ['keyAgreement'],
}];

const services = [{
'id' : 'dwn',
'type' : 'DecentralizedWebNode',
'serviceEndpoint' : {
'nodes' : dwnUrls,
'messageAttestationKeys' : ['#attest'],
'messageAuthorizationKeys' : ['#authz'],
'recordEncryptionKeys' : ['#encr']
}
}];

return { keys, services };
}
}
11 changes: 11 additions & 0 deletions packages/dids/tests/did-ion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ describe('DidIonApi', () => {
expect(key.type).to.exist;
}
});

it('works when using dwn configuration', async () => {
const ionCreateOptions = await DidIonApi.generateDwnConfiguration(['https://dwn.tbddev.org/dwn0']);

try {
// TODO: write specific assertions
const _didState = await DidIon.create(ionCreateOptions);
} catch(e) {
expect.fail(e.message);
}
});
});
8 changes: 1 addition & 7 deletions packages/web5/src/web5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ export class Web5 {
let ionCreateOptions;

if (dwnUrls.length > 0) {
ionCreateOptions = {
services: [{
id : 'dwn',
type : 'DecentralizedWebNode',
serviceEndpoint : { nodes: dwnUrls }
}]
};
ionCreateOptions = await DidIonApi.generateDwnConfiguration(dwnUrls);
}

const defaultProfileDid = await this.did.create('ion', ionCreateOptions);
Expand Down

0 comments on commit ea33290

Please sign in to comment.