-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Experiments with KeyStore IdentityStore
- Loading branch information
1 parent
27e4ab2
commit cca8825
Showing
7 changed files
with
1,487 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { AbstractIdentityStore, SerializedIdentity, Identity, Key } from 'daf-core' | ||
import Debug from 'debug' | ||
const debug = Debug('daf:orm:identity-store') | ||
|
||
export class IdentityStore extends AbstractIdentityStore { | ||
async get(did: string) { | ||
const identity = await Identity.findOne(did, { relations: ['keys'] }) | ||
if (!identity) throw Error('Identity not found') | ||
return identity | ||
} | ||
|
||
async delete(did: string) { | ||
const identity = await Identity.findOne(did) | ||
if (!identity) throw Error('Identity not found') | ||
debug('Deleting', did) | ||
await identity.remove() | ||
return true | ||
} | ||
|
||
async set(did: string, serializedIdentity: SerializedIdentity) { | ||
const identity = new Identity() | ||
identity.did = serializedIdentity.did | ||
identity.controllerKeyId = serializedIdentity.controllerKeyId | ||
identity.keys = [] | ||
|
||
for (const sKey of serializedIdentity.keys) { | ||
const key = new Key() | ||
key.kid = sKey.kid | ||
identity.keys.push(key) | ||
} | ||
await identity.save() | ||
|
||
debug('Saving', did) | ||
return true | ||
} | ||
|
||
async listDids() { | ||
const identities = await Identity.find() | ||
return identities.map(identity => identity.did) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AbstractKeyStore, SerializedKey, Key } from 'daf-core' | ||
|
||
import Debug from 'debug' | ||
const debug = Debug('daf:orm:key-store') | ||
|
||
export default class KeyStore extends AbstractKeyStore { | ||
async get(kid: string) { | ||
const key = await Key.findOne(kid) | ||
if (!key) throw Error('Key not found') | ||
return key | ||
} | ||
|
||
async delete(kid: string) { | ||
const key = await Key.findOne(kid) | ||
if (!key) throw Error('Key not found') | ||
debug('Deleting key', kid) | ||
await key.remove() | ||
return true | ||
} | ||
|
||
async set(kid: string, serializedKey: SerializedKey) { | ||
const key = new Key() | ||
key.kid = kid | ||
key.privateKeyHex = serializedKey.privateKeyHex | ||
key.publicKeyHex = serializedKey.publicKeyHex | ||
key.type = serializedKey.type | ||
debug('Saving key', kid) | ||
await key.save() | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"compilerOptions": { | ||
"preserveConstEnums": true, | ||
"sourceMap": true, | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"downlevelIteration": true, | ||
"declarationMap": true, | ||
"declaration": true, | ||
"composite": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true | ||
}, | ||
"exclude": ["**/__tests__/**/*", "**/build/**/*"], | ||
"references": [ | ||
{ "path": "../../packages/daf-core" }, | ||
{ "path": "../../packages/daf-data-store" }, | ||
{ "path": "../../packages/daf-debug" }, | ||
{ "path": "../../packages/daf-did-comm" }, | ||
{ "path": "../../packages/daf-did-jwt" }, | ||
{ "path": "../../packages/daf-ethr-did" }, | ||
{ "path": "../../packages/daf-fs" }, | ||
{ "path": "../../packages/daf-libsodium" }, | ||
{ "path": "../../packages/daf-node-sqlite3" }, | ||
{ "path": "../../packages/daf-resolver" }, | ||
{ "path": "../../packages/daf-resolver-universal" }, | ||
{ "path": "../../packages/daf-selective-disclosure" }, | ||
{ "path": "../../packages/daf-trust-graph" }, | ||
{ "path": "../../packages/daf-url" }, | ||
{ "path": "../../packages/daf-w3c" } | ||
] | ||
} |
Oops, something went wrong.