Skip to content

Commit

Permalink
add pair after unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
zzcwoshizz committed Mar 9, 2023
1 parent edb7d6b commit 2687ad9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-poets-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zcloak/did": patch
---

add pair after unlock
13 changes: 11 additions & 2 deletions packages/did/src/keys/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import type { DidUrl } from '@zcloak/did-resolver/types';
import type { Keyring } from '@zcloak/keyring';
import type { KeyringPair } from '@zcloak/keyring/types';
import type { DidKeys$Json } from './types';

import { Did } from '../did';
Expand All @@ -13,11 +14,15 @@ import { typeTransform } from '../utils';
export function restore(keyring: Keyring, json: DidKeys$Json, password: string): Did {
const keyRelationship = new Map<DidUrl, KeyRelationship>();

const pairs: KeyringPair[] = [];

json.keys.forEach((key, index) => {
const pair = keyring.addFromJson(key);
const pair = keyring.createFromJson(key);

pair.unlock(password);

pairs.push(pair);

const id: DidUrl = `${json.didUrl}#key-${index}`;
const controller: DidUrl[] = [`${json.didUrl}`];
const publicKey = pair.publicKey;
Expand All @@ -29,10 +34,14 @@ export function restore(keyring: Keyring, json: DidKeys$Json, password: string):
type: typeTransform(pair.type)
});
});
const pair = keyring.addFromJson(json.identifierKey);
const pair = keyring.createFromJson(json.identifierKey);

pair.unlock(password);

pairs.push(pair);

pairs.forEach((pair) => keyring.addPair(pair));

const details: IDidDetails = {
id: json.didUrl,
controller: new Set([json.didUrl]),
Expand Down

0 comments on commit 2687ad9

Please sign in to comment.