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

Packages/did: Add keyType Parameter to createDid Method #226

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
Commits
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
11 changes: 7 additions & 4 deletions packages/did/src/Did.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
PalletDidDidDetailsDidPublicKey,
PalletDidDidDetailsDidPublicKeyDetails,
PalletDidServiceEndpointsDidEndpoint,
RawDidLinkedInfo
} from '@cord.network/augment-api'

import {
Expand Down Expand Up @@ -515,21 +516,23 @@ export async function fetchFromMnemonic(mnemonic: string): Promise<DidDocument>
*/
adi-a11y marked this conversation as resolved.
Show resolved Hide resolved
export async function createDid(
submitterAccount: CordKeyringPair,
theMnemonic?: string,
keytype?: string,
adi-a11y marked this conversation as resolved.
Show resolved Hide resolved
_mnemonic?: string,
didServiceEndpoint?: DidServiceEndpoint[]
): Promise<{
mnemonic: string
document: DidDocument
}> {
const api = ConfigService.get('api')
const keyType = keytype ?? 'sr25519';

const mnemonic = theMnemonic? theMnemonic : mnemonicGenerate(24)
const mnemonic = _mnemonic? _mnemonic : mnemonicGenerate(24)
const {
authentication,
keyAgreement,
assertionMethod,
capabilityDelegation,
} = Keys.generateKeypairs(mnemonic,"ed25519")
} = Keys.generateKeypairs(mnemonic,keyType)
// Get tx that will create the DID on chain and DID-URI that can be used to resolve the DID Document.
const didCreationTx = await getStoreTx(
{
Expand All @@ -555,7 +558,7 @@ export async function createDid(
await Chain.signAndSubmitTx(didCreationTx, submitterAccount)

const didUri = getDidUriFromKey(authentication)
const encodedDid = await api.call.didApi.query(toChain(didUri))
const encodedDid : Option<RawDidLinkedInfo> = await api.call.didApi.query(toChain(didUri))
const { document } = linkedInfoFromChain(encodedDid)

if (!document) {
Expand Down