How can I import Node's built-in 'crypto' library to use in a Shopify Function?

How can I import Node's built-in 'crypto' library to use in a Shopify Function?

camsb
Shopify Partner
3 0 1

I'm working on a Shopify Function that can apply discounts via line item property/attribute data that can be added via our app.

 

The point of using 'crypto' would be to ensure that bad actors couldn't tamper with the line item properties and receive discounts they didn't earn.

 

I've been playing around with the idea of hashing the line item property data and generating an HMAC to do this.

 

However, I cannot figure out how to import the "crypto" library into the Function environment.

 

A basic import like:

import crypto from 'crypto';

 

Results in the following error:

 ERROR: Could not resolve "crypto"

 

What am I missing here? 

I've seen this thread which seems related, but it also seems to relate directly to Remix. 

 

Any ideas?

 

Thanks for any help / answers you can provide.

Replies 0 (0)