https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • k

    kian

    03/08/2023, 6:52 PM
    idk what the hotkey is for VSCode but 'goto' the type definition for
    subtle
    and see what's on it
  • k

    kian

    03/08/2023, 6:52 PM
    since it exists in workers-types
  • k

    kian

    03/08/2023, 6:52 PM
    so my first assumption is it's somehow using some other TS built-in types
  • k

    kian

    03/08/2023, 6:52 PM
  • d

    dave

    03/08/2023, 6:53 PM
    you are correct
  • k

    kian

    03/08/2023, 6:54 PM
    GottaLoveTS
  • s

    Skye

    03/08/2023, 6:54 PM
    Your tsconfig probably has
    lib
    in it?
  • d

    dave

    03/08/2023, 6:54 PM
    https://github.com/aimoda/random-id-hmac-bech32m/blob/main/tsconfig.json
  • s

    Skye

    03/08/2023, 6:55 PM
    I think it's
    DOM
    here doing that?
  • d

    dave

    03/08/2023, 6:56 PM
    and we have a winner
  • p

    Pato

    03/08/2023, 7:03 PM
    can i use the Node-RSA library in workers?
  • p

    Pato

    03/08/2023, 7:04 PM
    https://www.npmjs.com/package/node-rsa?activeTab=readme
  • w

    Walshy | Pages

    03/08/2023, 7:05 PM
    try it
  • p

    Pato

    03/08/2023, 7:09 PM
    im getting this:
    Copy code
    BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
    This is no longer the case. Verify if you need this module and configure a polyfill for it.
    
    If you want to include a polyfill, you need to:
            - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
            - install 'crypto-browserify'
    If you don't want to include a polyfill, you can use an empty module like this:
            resolve.fallback: { "crypto": false }
  • p

    Pato

    03/08/2023, 7:15 PM
    i tried editng my webpack config but its not working
  • p

    Pato

    03/08/2023, 7:15 PM
    Copy code
    js
    const path = require('path')
    
    module.exports = {
      entry: './src/index.ts',
      output: {
        filename: 'worker.js',
        path: path.join(__dirname, 'dist'),
      },
      devtool: 'cheap-module-source-map',
      mode: 'development',
      resolve: {
        extensions: ['.ts', '.tsx', '.js'],
         fallback: {
        "fs": false,
        "tls": false,
        "net": false,
        "path": false,
        "zlib": false,
        "http": false,
        "https": false,
        "stream": false,
        "crypto": false,
        // "crypto-browserify": require.resolve('crypto-browserify'), //if you want to use this module also don't forget npm i crypto-browserify 
      } 
      },
      module: {
        rules: [
          {
            test: /\.tsx?$/,
            loader: 'ts-loader',
            options: {
              // transpileOnly is useful to skip typescript checks occasionally:
              // transpileOnly: true,
            },
          },
        ],
      },
    }
  • c

    Crazy Rabbit

    03/08/2023, 7:46 PM
    Copy code
    js
    import * as path from 'path';
  • c

    Crazy Rabbit

    03/08/2023, 7:46 PM
    Use ES6 modules instead
  • u

    \ ឵឵឵

    03/08/2023, 7:57 PM
    Is there a way to force eviction of old versions of my worker after
    wrangler publish
    ? Occasionally I'm hitting old code up to 20m after deployment.
  • s

    Skye

    03/08/2023, 7:58 PM
    See https://www.cloudflarestatus.com/incidents/w8qglxs6ghy5 - it should normally be incredibly fast to update
  • d

    dave

    03/08/2023, 8:20 PM
    Is there a version of this written already for a CF Worker? https://developers.cloudflare.com/support/firewall/learn-more/configuring-token-authentication/#python-38
  • h

    HardAtWork

    03/08/2023, 8:58 PM
    Haven't tested it, but this should work:
    Copy code
    ts
    const enc = new TextEncoder();
    let key: CryptoKey;
    
    async function generateToken(message: string, separator: string, secret: string) {
      if(!key) {
        key = await crypto.subtle.importKey(
          "raw",
          enc.encode(secret),
          {
            name: "HMAC",
            hash: {
              name: "SHA-256"
            }
          },
          false,
          ["sign"]
        );
      }
      const timestamp = Math.floor(Date.now() / 1000).toString();
      return `${message}${separator}${timestamp}-${encodeURI(btoa(Array.from(new Uint8Array(crypto.subtle.sign(
        "HMAC",
        key,
        enc.encode(message + timestamp)
      ))).join((a, b) => a + String.fromCharCode(b), "")))}`;
    }
  • d

    dave

    03/08/2023, 8:59 PM
    thanks! I started to write my own, gonna test it soon too.
  • d

    dave

    03/08/2023, 8:59 PM
    one minor typo, I think you'll need
    Math.floor(Date.now() / 1000).toString();
    for the timestamp
  • h

    HardAtWork

    03/08/2023, 9:01 PM
    Oh, is it a second-based timestamp? My bad!
  • d

    dave

    03/08/2023, 9:03 PM
    I demand a full refund.
  • k

    kian

    03/08/2023, 9:06 PM
    we'll dock HAW's pay this month
  • h

    HardAtWork

    03/08/2023, 9:09 PM
    Also the encoder is supposed to be called
    enc
    .
  • h

    HardAtWork

    03/08/2023, 9:10 PM
    I'm very good at coding this late...
  • h

    HardAtWork

    03/08/2023, 9:10 PM
    Falls off the bar
1...232823292330...2509Latest