-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tdf3 + Nano = ❤️ #47
Merged
Merged
Tdf3 + Nano = ❤️ #47
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4453284
Basic merge, its working
ivanovSPvirtru a2652d5
Merge branch 'main' into feature/PLAT-1638-tdf3jsMigrate
ivanovSPvirtru a3957bb
caniuse-lite removed
ivanovSPvirtru 0923774
Fasade added
ivanovSPvirtru 556155b
Merge branch 'main' into feature/PLAT-1638-tdf3jsMigrate
ivanovSPvirtru c4a65d9
Package-lock regenerated
ivanovSPvirtru 1e86194
ignored canIuse cause its webpack sub-sub-dependency
ivanovSPvirtru 744a645
version reverted
ivanovSPvirtru a8207dd
version bumped
ivanovSPvirtru ce949ad
cli fix
ivanovSPvirtru ba28b80
eslint ts-ignore allowed
ivanovSPvirtru 7b1add8
licence check simple app fixed
ivanovSPvirtru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,67 @@ | ||
import { Client as ClientTdf3 } from '../tdf3/src/client'; | ||
import { DecryptParamsBuilder, EncryptParamsBuilder } from '../tdf3/src/client/builders'; | ||
import { TDFCiphertextStream } from '../tdf3/src/client/tdf-cipher-text-stream'; | ||
import { PlaintextStream } from '../tdf3/src/client/tdf-stream'; | ||
|
||
interface FileClientConfig { | ||
clientId: string, | ||
organizationName: string, | ||
oidcOrigin: string, | ||
kasEndpoint: string, | ||
clientSecret?: string, | ||
oidcRefreshToken?: string, | ||
} | ||
|
||
export class FileClient { | ||
private client: ClientTdf3; | ||
|
||
constructor({ clientId, clientSecret, oidcRefreshToken, organizationName, oidcOrigin, kasEndpoint }: FileClientConfig) { | ||
this.client = new ClientTdf3({ | ||
clientId, | ||
organizationName, | ||
clientSecret, | ||
oidcRefreshToken, | ||
kasEndpoint, | ||
virtruOIDCEndpoint: oidcOrigin, | ||
}); | ||
} | ||
|
||
private static setSource (source: ReadableStream | TDFCiphertextStream | Buffer | String | ArrayBuffer, params: EncryptParamsBuilder | DecryptParamsBuilder) { | ||
// @ts-ignore | ||
if(source.pipe !== undefined) { | ||
// @ts-ignore | ||
params.setStreamSource(source); | ||
} | ||
if(Buffer && Buffer.isBuffer(source)) { | ||
params.setBufferSource(source); | ||
} | ||
if(typeof source === 'string') { | ||
// there is not point to used tdf3.js withStringSource, after merging we have nanoTdf for that | ||
params.setFileSource(source); | ||
} | ||
if(source instanceof ArrayBuffer) { | ||
params.setArrayBufferSource(source) | ||
} | ||
return params.build(); | ||
} | ||
|
||
async encrypt(source: ReadableStream | Buffer | String | ArrayBuffer = '', users: string[] = [], params?: any ): Promise<TDFCiphertextStream> { | ||
const encryptParams = new EncryptParamsBuilder().withOffline().withUsersWithAccess(users); | ||
|
||
if (params) { | ||
return await this.client.encrypt(params); | ||
} | ||
// @ts-ignore | ||
return await this.client.encrypt(FileClient.setSource(source, encryptParams)); | ||
} | ||
|
||
async decrypt(source: ReadableStream | Buffer | String | ArrayBuffer = '', params?: any): Promise<PlaintextStream> { | ||
const decryptParams = new DecryptParamsBuilder(); | ||
|
||
if (params) { | ||
return await this.client.decrypt(params); | ||
} | ||
// @ts-ignore | ||
return await this.client.decrypt(FileClient.setSource(source, decryptParams)); | ||
} | ||
} |
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,8 @@ | ||
# renamed from license-checker-config.yml because GH gets confused and thinks this is the license file | ||
blacklisted-licenses: | ||
- gpl | ||
|
||
whitelisted-modules: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is spelled
facade
. But this is great! 👍