Options
All
  • Public
  • Public/Protected
  • All
Menu

HMAC signing utility. Methods are named after what it is to be signed, to allow for an easy to read code in the user application.

tutorial

https://wiki.foxycart.com/v/2.0/hmac_validation

example

const signer = new Signer(mySecret); // or const signer = new Signer(); signer.setSecret(mySecret); signer.signHtml('...'); // signs a URL signer.signFile("/var/www/html/src/.../index.html", "/var/www/html/target/.../index.html"); // signs an HTML file signer.signUrl("http://..."); // signs a URL

Hierarchy

  • Signer

Index

Constructors

constructor

  • new Signer(secret?: string | null): Signer
  • Creates an instance of this class.

    Parameters

    • Default value secret: string | null = null

      OAuth2 client secret for your integration.

    Returns Signer

Properties

Static cartExcludePrefixes

cartExcludePrefixes: string[] = ["h:", "x:", "__", "utm_"]

Static cartExcludes

cartExcludes: string[] = [// Analytics values"_","_ga","_ke",// Cart values"cart","fcsid","empty","coupon","output","sub_token","redirect","callback","locale","template_set",// Checkout pre-population values"customer_email","customer_first_name","customer_last_name","customer_address1","customer_address2","customer_city","customer_state","customer_postal_code","customer_country","customer_phone","customer_company","billing_first_name","billing_last_name","billing_address1","billing_address2","billing_city","billing_postal_code","billing_region","billing_phone","billing_company","shipping_first_name","shipping_last_name","shipping_address1","shipping_address2","shipping_city","shipping_state","shipping_country","shipping_postal_code","shipping_region","shipping_phone","shipping_company",]

Methods

setSecret

  • setSecret(secret: string): Signer
  • Sets the HMAC secret. It won't be possible to sign anything without this secret.

    Parameters

    • secret: string

      OAuth2 client secret for your integration.

    Returns Signer

    Signer to allow for convenient concatenation.

signFile

  • signFile(inputPath: string, outputPath: string, readFunc?: (arg0: string) => Promise<JSDOM>, writeFunc?: (path: string, content: string, callback: (err: any) => void) => void): Promise<ParentNode>
  • Signs a file asynchronously.

    Parameters

    • inputPath: string

      Path of the file to sign.

    • outputPath: string

      Path of the file where the signed result will be stored.

    • Default value readFunc: (arg0: string) => Promise<JSDOM> = JSDOM.fromFile

      a function that should read from file

        • (arg0: string): Promise<JSDOM>
        • Parameters

          • arg0: string

          Returns Promise<JSDOM>

    • Default value writeFunc: (path: string, content: string, callback: (err: any) => void) => void = fs.writeFile

      a function that should write to to file

        • (path: string, content: string, callback: (err: any) => void): void
        • Parameters

          • path: string
          • content: string
          • callback: (err: any) => void
              • (err: any): void
              • Parameters

                • err: any

                Returns void

          Returns void

    Returns Promise<ParentNode>

    a ParentNode object of the signed HTML.

signHtml

  • signHtml(htmlStr: string): string
  • Signs a whole HTML snippet.

    Parameters

    • htmlStr: string

      HTML snippet to sign.

    Returns string

    the HTML snippet signed.

signName

  • signName(name: string, code: string, parentCode?: string, value?: string | number): string
  • Signs input name.

    Parameters

    • name: string

      Name of the input element.

    • code: string

      Product code.

    • Default value parentCode: string = ""

      Parent product code.

    • Optional value: string | number

      Input value.

    Returns string

    the signed input name.

signUrl

  • signUrl(urlStr: string): string
  • Signs a query string. All query fields withing the query string will be signed, provided it is a proper URL and there is a code field

    Parameters

    • urlStr: string

      Full URL including the query string that needs to be signed.

    Returns string

    the signed query string.

signValue

  • signValue(name: string, code: string, parentCode?: string, value?: string | number): string
  • Signs input value.

    Parameters

    • name: string

      Name of the input element.

    • code: string

      Product code.

    • Default value parentCode: string = ""

      Parent product code.

    • Optional value: string | number

      Input value.

    Returns string

    the signed value.

Generated using TypeDoc