Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] Hilfe bei "crypto" (für neue Switchbot API)

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Hilfe bei "crypto" (für neue Switchbot API)

    This topic has been deleted. Only users with topic management privileges can see it.
    • Plasmachef
      Plasmachef last edited by Plasmachef

      Hallo Zusammen,

      habe grade erfahren, dass die API für Switchbot sich seit kurzem geändert hat (Link).
      In dieser wird die Authentifizierung anders gehandhabt als zuvor.

      Dieses Beispiel wird dazu angegeben (Quelle) :

      const token = "yourToken";
      const secret = "yourSecret";
      const t = Date.now();
      const nonce = "requestID";
      const data = token + t + nonce;
      const signTerm = crypto.createHmac('sha256', secret).update(Buffer.from(data, 'utf-8')).digest();
      const sign = signTerm.toString("base64");
      console.log(sign);
      

      Zeile 6 läuft hier auf einen Fehler bzgl. "crypto"

      Kann mir bitte jemand behilflich sein und mir das übersetzen, dass der ioBroker es versteht und ich damit die neue API ansprechen kann?

      Herzlichen Dank

      Plasmachef 1 Reply Last reply Reply Quote 0
      • Plasmachef
        Plasmachef @Plasmachef last edited by

        folgende Lösung habe ich für Zeile 6 gefunden:

        const signTerm = require('crypto').createHmac('sha256', secret).update(Buffer.from(data, 'utf-8')).digest();
        

        Kann mir das bitte noch jemand bestätigen?

        Danke 🙂

        OliverIO 1 Reply Last reply Reply Quote 0
        • OliverIO
          OliverIO @Plasmachef last edited by OliverIO

          @plasmachef
          Wahrscheinlich hätte es gereicht ganz am Anfang die folgende Zeile einzufügen

          const crypto = require(“crypto”);
          

          Wobei in der Node Doku das so steht
          https://nodejs.org/api/crypto.html

          const crypto = require(“node:crypto”);
          
          Plasmachef 1 Reply Last reply Reply Quote 0
          • Plasmachef
            Plasmachef @OliverIO last edited by

            @oliverio
            Herzlichen Dank 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate

            799
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            2
            4
            170
            Loading More Posts
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes
            Reply
            • Reply as topic
            Log in to reply
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
            The ioBroker Community 2014-2023
            logo