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

Build KeychainProgram #216

Open
benjaminpreiss opened this issue Oct 8, 2023 · 0 comments · May be fixed by #217
Open

Build KeychainProgram #216

benjaminpreiss opened this issue Oct 8, 2023 · 0 comments · May be fixed by #217

Comments

@benjaminpreiss
Copy link
Collaborator

benjaminpreiss commented Oct 8, 2023

We build a new KeychainProgram that extends Program and can be used by devs to handle keys for them.

How might this be implemented?

 import { Keychain } from '@peerbit/keychain' 

class KeychainDB extends Program implements Keychain, EncryptionProvider ? 
{
    @field({type:  Documents<Key>}}
    keys: Documents<Key>

    async open() {

          await this.keys.open({ encryption: new EncryptionProvider(this) }} // create a encryption provider from 'this' because 'this' implements Keychain interface 
   }

   async addKey(key: Key) {
        return this.keys.put(key, { encryption: { specific encryption options }}
   }

}

... And how could we possibly use it?

import { KeychainDB } from '@peerbit/keychain'


class MySpecialDBAndKeychain extends Program 
{
    @field({type: KeychainProgram}}
    keychain: KeychainProgram

    @field({type: Posts}}
    posts: Posts

    async open() {
          await this.keychain.open()
          await this.posts.open( { encryption: this.keychain.encryption }  )  // use custom encryption provider  (layer 1)
   }

   async createPost(content: string) {
        return this.posts.put(new Post(content))
   }

}

And then the Posts Document can use the passed encryption and decryption provider to store encrypted data.

@benjaminpreiss benjaminpreiss linked a pull request Oct 9, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants