Skip to content

Plugins API #23

@olastor

Description

@olastor

In olastor/age-plugin-fido2-hmac#20 I created the PoC mentioned in #16 and while doing that I added a simple plugin API to a fork of typage (see olastor@156a9b1). I am wondering if there could be an official plugin API in this project. I tried to create a simple implementation that is close to FiloSottile/age#580 .

Every plugin would need to implement the following data structure:

export interface Plugin<Recipient, Identity> {
  name: string
  handleRecipient: (recipientBytes: Uint8Array) => Recipient
  handleIdentityAsRecipient: (identityBytes: Uint8Array) => Recipient
  handleIdentity: (identityBytes: Uint8Array) => Identity
  wrapFileKey: (recipient: Recipient, fileKey: Uint8Array) => Stanza | Promise<Stanza>
  unwrapFileKey: (identity: Identity, stanzas: Stanza[]) => Uint8Array | Promise<Uint8Array | null> | null
}

For the Encrypter / Decrypter classes, you'd then need to call .registerPlugin(plugin). There'd also be a new addIdentity() method in the encrypter that uses handleIdentityAsRecipient.

There are probably many ways this API could be implemented and the code I created in the fork is still a bit "sketched", lacking validations, tests etc. If a modified version of this would be useful for having in the main package, I could look into polishing it and creating a PR, though. But maybe also a totally different way of doing it could be considered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions