-
Notifications
You must be signed in to change notification settings - Fork 518
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
AES256GCM decrypt: replace Observable with Promise #778
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c961275
AES256GCM decrypt: replace Observable with Promise
bangtoven 6107ab1
WalletSDKRelay
bangtoven acebeca
fix linter
bangtoven 349616e
prettier
bangtoven d242915
hmmmmm
bangtoven bdf1b16
rejects.toThrowError
bangtoven 4190870
rejects.toThrow
bangtoven 0d0ceae
update comment
bangtoven c41d68c
return promise
bangtoven 23ed8a5
use async / await instead
bangtoven 72ee522
prettier
bangtoven 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
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
// Copyright (c) 2018-2022 Coinbase, Inc. <https://www.coinbase.com/> | ||
// Licensed under the Apache License, version 2.0 | ||
|
||
import { Observable } from "rxjs"; | ||
|
||
import { hexStringToUint8Array, uint8ArrayToHex } from "../util"; | ||
|
||
/** | ||
|
@@ -63,15 +61,10 @@ export async function encrypt( | |
* @param cipherText hex string representation of bytes in the order: initialization vector (iv), | ||
* auth tag, encrypted plaintext. IV is 12 bytes. Auth tag is 16 bytes. | ||
* @param secret hex string representation of 32-byte secret | ||
* | ||
* TODO: Update rxjs for promises | ||
Comment on lines
-66
to
-67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌 |
||
*/ | ||
export function decrypt( | ||
cipherText: string, | ||
secret: string, | ||
): Observable<string> { | ||
export function decrypt(cipherText: string, secret: string): Promise<string> { | ||
if (secret.length !== 64) throw Error(`secret must be 256 bits`); | ||
return new Observable<string>(subscriber => { | ||
return new Promise<string>((resolve, reject) => { | ||
void (async function () { | ||
const secretKey: CryptoKey = await crypto.subtle.importKey( | ||
"raw", | ||
|
@@ -101,10 +94,9 @@ export function decrypt( | |
concattedBytes, | ||
); | ||
const decoder = new TextDecoder(); | ||
subscriber.next(decoder.decode(decrypted)); | ||
subscriber.complete(); | ||
resolve(decoder.decode(decrypted)); | ||
} catch (err) { | ||
subscriber.error(err); | ||
reject(err); | ||
} | ||
})(); | ||
}); | ||
|
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.
not sure how this worked before as well.
error
's message is not equal toexpected error
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.
cc @erin-at-work