const BLOCK_RPC = "https://public-node-api.klaytnapi.com/v1/cypress" const Caver = require("caver-js") const caverClient = new Caver(BLOCK_RPC); const Hash = require('eth-lib/lib/hash') const crypto = require("crypto"); const http = require('http'); const https = require('https'); const kip_url = '***KIP URL***'; (async () => { // KAS related input const chainId = '***CHAIN ID***'; const accessKey = '***YOUR KAS ACCESS KEY***' const secretKey = '***YOUR KAS SECRET KEY***' const authToken = 'Basic ' + btoa(`${accessKey}:${secretKey}`); // write your input here const timestamp = '***YOUR TIMESTAMP***' //e.g. 1675843358759 const deployerAddress = "***YOUR KIP DEPLOYER ADDRESS***" const contractAddress = "***YOUR KIP ADDRESS***" // logic to verify signature const message = `${timestamp}${deployerAddress}${contractAddress}` const encryptedHashRaw = crypto.createHash("sha256").update(message).digest("hex"); console.log("encrypted hash for apply : ", encryptedHashRaw) const prefixedEncryptedHash = `\x19Klaytn Signed Message:\n`+ encryptedHashRaw.length + encryptedHashRaw const hashedPrefixedEncryptedHash = Hash.keccak256(prefixedEncryptedHash) const signature = await signByDeployer(chainId, authToken, hashedPrefixedEncryptedHash) const hashedPrefixedEncryptedHashSignature = JSON.parse(signature.toString()).signedData; console.log("signature : ", hashedPrefixedEncryptedHashSignature) // raw message & signature : preFixed option= False const recoveredAddress = await caverClient.klay.accounts.recover(encryptedHashRaw, hashedPrefixedEncryptedHashSignature); if (recoveredAddress === deployerAddress) { console.log("validation passed use values below ") console.log({ timestamp, walletAddress : deployerAddress, contractAddress : contractAddress, signature : hashedPrefixedEncryptedHashSignature, }) console.log("----------------------------------") } else { console.log("validation failed") } })(); async function signByDeployer(chainId, authToken, hash){ const method = 'POST'; const headers = { 'x-chain-id': chainId, 'Authorization': authToken, 'Content-Type': 'application/json' }; const data = { data: hash }; const resp = await sendHttpRequest(kip_url, method, headers, data) return resp } function sendHttpRequest(url, method, headers, data) { return new Promise((resolve, reject) => { const protocol = url.startsWith('https') ? https : http; const options = { method: method, headers: headers, }; const req = protocol.request(url, options, (res) => { let responseText = ''; res.setEncoding('utf8'); res.on('data', (chunk) => { responseText += chunk; }); res.on('end', () => { resolve(responseText); }); }); req.on('error', (error) => { console.log("error : ", error) reject(error); }); if (data) { req.write(JSON.stringify(data)); } req.end(); }); }