Skip to content
Snippets Groups Projects

OCM key - svdx id mapping OP#252

Merged Alexey Lunin requested to merge feat/252-public-private-key-mapping into main
All threads resolved!
@@ -65,6 +65,7 @@ import {
SvdxDidResolver,
SvdxModule,
DefaultIpfsClient,
SvdxRecordsApi,
} from "@vereign/credo-did-svdx";
import { SubjectInboundTransport } from "./askar/transports/agent.subject.inbound.transport";
@@ -204,9 +205,45 @@ export const generateDidWeb = async ({
console.log(JSON.stringify(didDocumentInstance.toJSON(), null, 2));
};
export const generateRandomDidSvdx = async (agent: Agent) => {
const seed = crypto.randomBytes(46).toString("hex");
return generateDidSvdx({ agent, seed });
export const generateDidSvdxForEmail = async (agent: Agent, email: string) => {
const activeKeySeed = crypto.randomBytes(46).toString("hex");
const nextKeySeed = crypto.randomBytes(46).toString("hex");
const activeKey = await generateKey({ seed: activeKeySeed, agent });
const nextKey = await generateKey({ seed: nextKeySeed, agent });
const WalletKeyPair = createWalletKeyPairClass(agent.context.wallet);
const keyPair = new WalletKeyPair({
id: `key-1`,
controller: `did:svdx:${activeKey.fingerprint}`,
key: activeKey,
wallet: agent.context.wallet,
});
const didResult = await agent.dids.create({
method: "svdx",
options: {
inceptionKey: activeKey,
nextKey: nextKey,
signer: { signer: () => keyPair.signer() },
},
});
if (!didResult.didState.didDocument || !didResult.didState.did) {
throw new Error("Could not create did svdx");
}
const svdxApi: SvdxRecordsApi = agent.modules["svdx"];
await svdxApi.save({
email: email,
did: didResult.didState.did,
activeKey: activeKey.publicKeyBase58,
activeKeySeed: activeKeySeed,
nextKey: nextKey.publicKeyBase58,
nextKeySeed: nextKeySeed,
});
return didResult;
};
export const generateDidSvdx = async ({
Loading