Help Center/ KooDrive/ API Reference/ Appendixes/ Process of Generating ProofCode
Updated on 2026-03-18 GMT+08:00

Process of Generating ProofCode

The device and server use the same file segment to calculate the digest. If the digest values calculated by the two parties are the same, the user has the file. This prevents credential stuffing from other users' files using sha256. In the case of an exception, if the file size is 0, this value does not need to be calculated.

Step 1: Generate a Storage Proof Seed (ProofSeed)

ProofSeed = HexEncode(SHA256(originValue))
  • originValue: When the appid is used for authentication, the value is obtained from the X-User-Id header in the request. In other authentication schemes, the value is obtained from the Authorization header in the request.
  • SHA256(String): For a message of any length, SHA256 generates a 256-bit hash value, which is called a message digest.
  • HexEncode(ByteArray): Base16 encoding function for returning a digest consisting of lowercase letters. Each byte you enter is expressed as two hexadecimal characters.

Step 2: Determine the Binary File Fragment Involved in the Storage Proof Calculation

Calculate the start and end positions of the binary file involved in the calculation.

Start = LongValueUnsigned(ByteSub(SHA256(ProofSeed),24,32))%size;
End = Start+8>=Size?Size:Start+8;
  • SHA256(String): For a message of any length, SHA256 generates a 256-bit hash value, which is called a message digest.
  • ByteSub(ByteArray,Integer,Integer): bytes in the specified range are extracted from the digest value. In this scenario, SHA256 returns 32 bytes. The last 8 bytes of the digest value are used, that is, the bytes in the range [24, 32).
  • LongValueUnsigned (BitSet): the byte array is converted into an 8-byte integer. When implementing this function, the sign bit of the first byte must be removed to ensure that a positive integer is returned.
  • size: size of the file (unit: byte).
  • The binary file fragment involved in the storage proof calculation is the binary file fragment corresponding to the [Start, End) range.

Step 3: Calculate the Storage Proof

Obtain the corresponding array from the corresponding position of the binary file based on the binary fragment.

Data = readFile(file, start, end);
proofCode = HexEncode(SHA256(Data))
  • readFile(File,Integer,Integer): the byte array is read from the specified range of the file.
  • SHA256(ByteArray): For a message of any length, SHA256 generates a 256-bit hash value, which is called a message digest.
  • HexEncode(ByteArray): Base16 encoding function for returning a digest consisting of lowercase letters. Each byte you enter is expressed as two hexadecimal characters.