wallee-payment / typescript-sdk

The wallee TypeScript library wraps around the wallee API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support option to use native node modules for crypto-js, bluebird (and request)

thomasklein-winemaker opened this issue · comments

"dependencies": {
        "bluebird": "^3.5.0",
        "crypto-js": "^3.1.8",
        "request": "^2.81.0",
}

While I understand that all node versions should be supported it would be convenient to have them somehow optional. The main reason is to reduce the overall size of a code bundle that uses the sdk. While a smaller bundle size is generally a good thing there's also an economic aspect to it in environments such as AWS Lambda. Smaller bundles = less parsing=execution time + less reserved memory needed.

  • bluebird: Native promises are supported since node 0.12
  • crypto-js: the biggest dependency of all. In case the node runtime is compiled with the openssl crypto module (e.g. the AWS lambda node versions are) not necessary.

Optional

  • request: while native http or https could be used instead I understand the inconvenience of using those low-level apis

Do you see any possibility?

@thomasklein-winemaker We will look into how we can optimize the SDK.

For the moment I stopped using the SDK as a code dependency (I still use the types, however, which are super useful).

Generation of MAC Value for authentication with "native" (if node is compiled with the openssl crypto module) crypto module:

const crypto = require(`crypto`)

function base64Decode({ value, targetEncoding = `binary`, }) {
  const result = Buffer.from(value, `base64`)

  if (targetEncoding === `binary`) {
    return result
  } else {
    return result.toString(targetEncoding)
  }
}
function getMacValue({ userID, apiKey, method, path, timestamp, }) {
  const macVersion = 1
  const data = [macVersion, userID, timestamp, method, path,].join(`|`)
  const hmac = crypto.createHmac(
    `sha512`, Buffer.from(apiKey, `base64`)
  )

  hmac.update(data)

  return hmac.digest(`base64`)
}