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

Crypto payments #284

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Crypto payments #284

wants to merge 14 commits into from

Conversation

AlanBreck
Copy link
Collaborator

ALERT: this PR is still very much a WIP. Once out of draft mode, it will be submitted for security/privacy review.

Resolves #216

This PR introduces a second payment provider, Radom, in order to accept crypto payments.

renovate bot and others added 11 commits October 17, 2024 17:45
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…est to cf6bad7 (#281)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@AlanBreck AlanBreck self-assigned this Oct 23, 2024
This was referenced Oct 23, 2024
@AlanBreck AlanBreck linked an issue Oct 23, 2024 that may be closed by this pull request
Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

few comments/questions, but overall looking good

"tweetnacl": "1.0.3",
"typescript": "5.6.2",
"vite": "5.4.6"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "3.1.2",
"@tsconfig/svelte": "5.0.4"
"@tsconfig/svelte": "5.0.4",
"msw": "2.3.1",
Copy link
Member

Choose a reason for hiding this comment

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

These were already previously audited - no concerns with the additional dependencies.


const typedVariants = variants ?? ([] as Array<StrongVariant>);

// TODO: (maybe) return error if could not find all products in DB
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth creating an issue for this TODO and referencing it in the comment?

const encryptShippingData = async (
recipientInformation: App.Recipient
): Promise<EncryptedShippingAddress> => {
const encryptionKey = generateKey();
Copy link
Member

Choose a reason for hiding this comment

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

no concerns with this usage of cryptography here. We're relying on tweetnacl secretbox underneath for this

displayName: getCustomShippingName(rate)
})) as Array<ShippingRate>;
};

Copy link
Member

Choose a reason for hiding this comment

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

nit - looks like GH doesn't like how I'm indenting this

Suggested change
# The reason we encrypt this data is because we don't want to retain the shipping data longer than
# necessary so the easiest way to do this is to pass it through by the service providers such that once
# payment is complete we can decrypt it and get rid of it and the decryption key while still being able
# to pass it to printful after the payment is completed.

Helpful comment to explain what's going on in better detail here since it's a relatively key architectural decision that we made here

};
});

// TODO: need to figure out how to let users select shipping option?
Copy link
Member

Choose a reason for hiding this comment

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

this one seems like it would be good to open a follow up issue for too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This on is on Radom to implement. I've put in a request for them to match Stripe's functionality for this.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, sounds like nothing to change to our site then just to their page? Would we need to send the additional shipping options to them too?

Copy link
Member

Choose a reason for hiding this comment

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

Also, btw this is a nit - non-blocker


export const PROVIDER_NAME = 'radom';

export async function radomApi<T = any>(resourcePath: string, options?: RequestInit): Promise<T> {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here saying this code should only be called by backend code?

I want to avoid us accidentally using this in front end code and leaking the API key

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely. Will also look into leveraging $lib/server: https://svelte.dev/docs/kit/server-only-modules#Your-modules

[key in Network]?: Record<string, string>
}

const TestnetTokens: Tokens = {
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure this is done somewhere, but I've not come across it yet. Do we check the environment we're in to decide which of these arrays get used somewhere? Just want to make sure we aren't accidentally letting people pay with testnet tokens in prod (or prod in staging/local)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

perfect thanks

@@ -1,4 +1,4 @@
/** @type {import("@sveltejs/kit").ParamMatcher} */
export function match(param) {
return /^cs_[a-zA-Z0-9_-]+$/.test(param);
return /^(?:cs_)?[a-zA-Z0-9_-]+$/.test(param);
Copy link
Member

Choose a reason for hiding this comment

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

since this appears to be a regex matcher, it probably makes sense to length limit here to 36 characters to avoid a ReDoS issue

Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

#284 (comment)
and #284 (comment) would be good to get fixed before we merge, but aren't blockers because they're not direct security vulnerabilities. Looking through the rest are nit's so going to approve

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.

Accept BAT as payment
2 participants