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

SKUs SDK Changes to Support Receipt Submission #13820

Merged
merged 5 commits into from
Aug 31, 2022

Conversation

husobee
Copy link
Contributor

@husobee husobee commented Jun 16, 2022

Implementation of generic receipt submission client for SKUs SDK, including WASM bindings which will support various vendor (google, apple) payment confirmations for in-app purchases.

Resolves brave/brave-browser#23167
Security / privacy review: https://github.com/brave/security/issues/933

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@husobee husobee requested review from bsclifton and evq June 16, 2022 14:16
@husobee husobee self-assigned this Jun 16, 2022
@bsclifton bsclifton force-pushed the bh-skus-sdk-submit-receipt branch 2 times, most recently from cce3eed to 92d22fb Compare July 1, 2022 17:55
@bsclifton
Copy link
Member

bsclifton commented Jul 5, 2022

We don't have an integration using this... yet! But #13387 will definitely be using this code 😄 See more details in https://github.com/brave/security/issues/933#issuecomment-1169200217

Code LGTM - but would leave to @evq or another person to review also (since I helped 😄). @husobee there were some comments by @spylogsster in case you missed them above

Copy link
Member

@thypon thypon left a comment

Choose a reason for hiding this comment

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

.

@evq
Copy link
Member

evq commented Aug 2, 2022

I don't love all the repeated mangling we're doing at the moment to convert errors into something that wasm-bindgen is happy with, I think we should look into whether the resolution linked at the bottom of this issue helps clean things up [1]

[1] rustwasm/wasm-bindgen#1004

@husobee husobee requested a review from a team as a code owner August 16, 2022 15:22
@husobee husobee requested a review from evq August 16, 2022 15:24
Correcting serde unwrap in SDK.
Utilizing APIError structure in InternalError implementation
Propogate endpoint specific error conditions through wasm
removing ExternalPurchase errors in favor of generic api errors
fixing cxx rust errors to match sdk
@bsclifton bsclifton removed the request for review from a team August 30, 2022 16:33
Copy link
Contributor

@rillian rillian left a comment

Choose a reason for hiding this comment

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

r=me for rust deps. Style suggestions below.

}
ffi::SkusResult::UnhandledStatus => {
skus::errors::InternalError::UnhandledStatus(skus::models::APIError {
code: 499,
Copy link
Contributor

Choose a reason for hiding this comment

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

This used to be 699, not 499 like BadRequest. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok(None) => callback.0(callback_state.into_raw(), ffi::SkusResult::Ok, ""),
Err(e) => callback.0(callback_state.into_raw(), e, ""),
}
}

#[repr(transparent)]
pub struct CredentialSummaryCallback(
pub extern "C" fn(
pub extern "C" fn(
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/rust-lang/rust.vim is the plugin I have been using, and it keeps adding this one particular whitespace in ;)

I'll disable the formatting on save to change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Wild, I've never seen that! I filed rust-lang/rustfmt#5525

components/skus/browser/rs/lib/src/errors.rs Outdated Show resolved Hide resolved
components/skus/browser/rs/lib/src/sdk/orders.rs Outdated Show resolved Hide resolved
builder.uri(format!("{}/v1/orders/{}/submit-receipt", self.base_url, order_id));

let receipt_bytes: Vec<u8> = receipt.as_bytes().to_vec();
let req = builder.body(receipt_bytes).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the unwrap() calls here. They're fine for static input, which I guess is the case here, but you have to read the http crate source to determine that. This should be mapped to an error.

However, since the pattern isn't new to this patch, I'm ok with this as-is if you file a follow-up issue about addressing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

components/skus/browser/rs/lib/src/sdk/orders.rs Outdated Show resolved Hide resolved
components/skus/browser/rs/wasm/src/lib.rs Outdated Show resolved Hide resolved
components/skus/browser/rs/wasm/src/lib.rs Outdated Show resolved Hide resolved
components/skus/browser/rs/wasm/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 1117 to +1118
name = "zeroize"
version = "1.4.3"
version = "1.3.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Downgrade to match challenge-bypass-ristretto and curve25519-dalek because of api drift in 1.4. Ok.

@bsclifton bsclifton added this to the 1.45.x - Nightly milestone Aug 30, 2022
@husobee husobee requested a review from a team as a code owner August 30, 2022 20:13
@husobee husobee merged commit 413e31c into master Aug 31, 2022
@husobee husobee deleted the bh-skus-sdk-submit-receipt branch August 31, 2022 12:28
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.

Add SKU SDK wrapper method for SubmitReceipt
6 participants