UMIVERSE SDK
  • UMIVERSE SDK Doc
    • Overview
    • Configure Secret Key and API Domain
    • Sync Account
      • OAuth login
        • Preparations for OAuth
        • Use Authorization_Code to get UMI_UID
        • Decrypt Authorization Code
          • AES Decrypt
    • Dive Points
      • Increase DivePoint
        • API
      • Mission System
        • Request task panel view in H5 game
    • Game Recharge
      • Initiate Recharge Request
      • Handle Recharge Completion
  • Signature
    • Typescript
    • PHP
    • Java
    • C++
  • SDK DEMO
  • Legacy
    • API Key/Secret
    • SignUp & SignIn
    • Get UMI UID
    • Authentication
    • Umiverse Features
      • Mint
      • Send a server-generated item to Umi account
      • Get all items that the player can put up for sale
      • Send an item to a player
      • Deduct an item from a player
    • Redirect
  • Developer Console
    • Add Game Information
Powered by GitBook
On this page

Signature

Umiverse SDK features require a signature to use. To implement the md5 sign of an object parameter in TypeScript, we need to sort the object parameters in name=value&name=value format and add a timestamp to prevent data tampering. Then, we can use the md5 algorithm to generate the sign. Here's an example implementation:

import md5 from 'md5';

interface Params {
  [key: string]: any;
}

function generateSign(params: Params, secretKey: string): string {
  const timestamp = Math.floor(Date.now() / 1000).toString();
  const sortedParams = Object.keys(params).sort().reduce((acc, key) => {
    acc[key] = params[key];
    return acc;
  }, {});
  sortedParams['timestamp'] = timestamp;
  const signStr = Object.keys(sortedParams).map(key => `${key}=${sortedParams[key]}`).join('&') + secretKey;
  return md5(signStr);
}

In this implementation, we define an interface Params to represent the object parameter. The generateSign function takes two parameters: the object parameter params and the secret key secretKey. The function first generates a timestamp and adds it to the sorted object parameter. It then concatenates the name-value pairs with the secret key and generates the md5 hash of the resulting string. The function returns the md5 hash as the sign.

PreviousHandle Recharge CompletionNextTypescript

Last updated 5 months ago