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

Store encrypted files on IPFS and link to POD attributes #1328

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hieronx
Copy link
Contributor

@hieronx hieronx commented May 1, 2023

Description

This pull request adds an encrypted-file attribute type to loans. When a file is added, this is encrypted using a randomly generated key, pinned on IPFS, and both the IFPS hash and the key are stored in the POD document. This way anyone with access to the POD document can download the file and decrypt it.

Closes #1438

Approvals

  • Dev
  • Dev
  • Designer
  • Product

Screenshots

Impact

@@ -338,7 +356,7 @@ function IssuerCreateLoan() {
/>
{isLoggedIn ? (
<>
<PageSection titleAddition="Select a template to enter the asset details.">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to this PR but I noticed this line should have been removed already

@@ -137,6 +138,23 @@ function TemplateField({ label, name, input }: TemplateFieldProps) {
max={input.max}
/>
)
case 'encrypted-file':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider also adding a file type, which is not encrypted and used as a public field. Or even just having only a file type and encrypting or not depending on whether the section is public.

})
)
(
await Promise.all(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be async to allow the encrypting and pinning within this method.

)
}

// Source: https://gist.github.com/chrisveness/43bcda93af9f646d083fad678071b90a
async function aesGcmEncrypt(plaintext: string, password: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This of course should be moved somewhere else. And maybe replaced by a higher level library that does this.

@@ -6,8 +6,8 @@ export type LoanTemplateAttribute = {
label: string
type: {
primitive: 'string' | 'number'
statistics: 'categorical' | 'continuous' | 'ordinal' | 'descrete'
constructor: 'String' | 'Date' | 'Number'
statistics?: 'categorical' | 'continuous' | 'ordinal' | 'discrete'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Small typo here
  2. I think this should be optional. It doesn't make sense to specify statistics for file uploads, and there will likely be other input types in the future for which there's no possible statistics.

function getMetadata<T = any>(uri: string): Observable<T | T[] | null> {
const url = parseMetadataUrl(uri)
if (!url) {
return from([])
}
return inst.getMetadataObservable<T>(url)
return inst.getJsonObservable<T>(url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all can be use a little refactoring. getMetadata doesn't seem specific to metadata, works for any file. getMetadataObservable really is a getter specifically for JSON files.

@github-actions
Copy link

github-actions bot commented May 1, 2023

PR deployed in Google Cloud
URL: https://app-pr1328.k-f.dev
Commit #: 1e5ad77
To access the functions directly check the corresponding deploy Action

@annamehr annamehr requested a review from jpangelle May 25, 2023 12:30
@annamehr annamehr requested review from sophialittlejohn and removed request for jpangelle June 8, 2023 12:25
@sophialittlejohn sophialittlejohn removed their request for review June 9, 2023 16:08
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 this pull request may close these issues.

Store encrypted files on IPFS and link to POD attributes
2 participants