웹훅 무결성 검증

해시키를 설정하여 웹훅 무결성을 검증할 수 있습니다. 해시키는 90일 동안 사용이 가능하며, 키가 만료되면 웹훅 전송이 중단됩니다. 따라서 키가 만료되지 않도록 90일 전에 키를 업데이트 해주셔야 합니다. 만료 후 키를 업데이트 하게 되면 웹훅 전송이 즉시 재개됩니다. 웹훅의 해시키는 임의의 값으로 설정할 수 있으며 최소 32바이트 길이의 키를 사용하도록 권장합니다.


해시키 설정하기

1. 콘솔에서 설정

웹훅 등록 시, 무결성 검증 활성화를 선택하세요. 사용할 해시키 값을 입력하여 설정할 수 있습니다.


2. API로 설정

웹훅 등록 API를 호출하여 웹훅을 등록합니다. 임의의 hashKey를 입력하여 설정할 수 있습니다.


해시키 수정하기

1. 콘솔에서 설정

웹훅 페이지에서 더보기 버튼을 클릭하세요. 수정하기 버튼을 클릭하여 해시키를 수정할 수 있습니다.


2. API로 설정

웹훅 정보 수정 API를 호출하여 웹훅 정보를 수정합니다. hashKey를 입력하여 수정할 수 있습니다.


예제 코드

1. 입금

webhookTargetDataHash 가 추가되어 웹훅이 전달됩니다. 해싱 대상은 웹훅의 데이터만 해당됩니다.

[
  {
    "webhookIdx": 172,
    "webhookTargetIdx": 347051,
    "webhookTargetDataScheme": "TRANSACTION_1",
    "webhookTargetDataHash": "OKJ5pUHVa24qBW/JdOMKMZ/KYJJXcnYpiUJj+XE0kMQ=", // <-- 해시값
    "data": {
      "memo": null,
      "txid": "0xb465105b5ab17684ed31b618fcb03755f9e2bea0ac37c7b988937d9c4f4b727d",
      "type": "DEPOSIT",
      "uuid": "a9cf3657-8c81-45bc-bbef-0b4facb15205",
      "nonce": 45699,
      "amount": "0.10000000000000000000",
      "status": "FINALIZED",
      "symbol": "KLAY",
      "usedFee": "0.00077500000000000000",
      "toAddress": "0x00732A92d2bf0d54057e6b28be5bcFb409df8E72",
      "failedDate": null,
      "blockHeight": "122645065",
      "createdDate": "2023-05-16T07:30:06.807Z",
      "fromAddress": "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4",
      "outputIndex": 0,
      "toAddresses": [
        "0x00732A92d2bf0d54057e6b28be5bcFb409df8E72"
      ],
      "modifiedDate": "2023-05-16T07:30:15.000Z",
      "finalizedDate": "2023-05-16T07:30:16.000Z",
      "fromAddresses": [
        "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4"
      ],
      "contractAddress": null,
      "feePayerAddress": "0x73b14def9a8b01525cb4eff356e01ce611d356aa",
      "unfinalizedDate": "2023-05-16T07:30:07.000Z",
      "useFeeDelegation": true,
      "transactionCurrency": {
        "krw": "226.99282922",
        "usd": "0.16965089"
      }
    }
  }
]


2. 해싱 코드

옥텟에서 해싱하는 코드입니다. 전문 암호화에서 사용하는 HMAC 코드와 동일합니다.

function hash(data: Record<string, any>, hashKey: string): string {
  const message = JSON.stringify(data);
  return createHmac('sha256', hashKey).update(message).digest('base64');
}


3. 검증용 데이터

[
  {
    "webhookIdx": 172,
    "webhookTargetIdx": 347066,
    "webhookTargetDataScheme": "TRANSACTION_1",
    "data": {
      "memo": null,
      "txid": "0x46ac495ea3374510bb3dfd97cc28baa31526196cf19093bc62206779296979a6",
      "type": "DEPOSIT",
      "uuid": "ddb7d66e-dd67-4bef-8f68-fb70aab652db",
      "nonce": 45705,
      "amount": "0.10000000000000000000",
      "status": "FINALIZED",
      "symbol": "KLAY",
      "usedFee": "0.00077500000000000000",
      "toAddress": "0x01ac8A8624B44Ede413Dd3390f1E48A8d512bD2A",
      "failedDate": null,
      "blockHeight": "122645073",
      "createdDate": "2023-05-16T07:30:15.790Z",
      "fromAddress": "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4",
      "outputIndex": 0,
      "toAddresses": [
        "0x01ac8A8624B44Ede413Dd3390f1E48A8d512bD2A"
      ],
      "modifiedDate": "2023-05-16T07:30:26.000Z",
      "finalizedDate": "2023-05-16T07:30:26.000Z",
      "fromAddresses": [
        "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4"
      ],
      "contractAddress": null,
      "feePayerAddress": "0x73b14def9a8b01525cb4eff356e01ce611d356aa",
      "unfinalizedDate": "2023-05-16T07:30:16.000Z",
      "useFeeDelegation": true,
      "transactionCurrency": {
        "krw": "226.99282922",
        "usd": "0.16965089"
      }
    }
  }
]
hash key: d0fd4a49b59dc3aef63ede1e6f4c32a15e94609df0c0fba00b2271080dd13435
webhookTargetDataHash: hiphZyBZ+jtKS4/XKiDAOagA7ex2S3Kg34+h1OqEAs8=


4. 전달될 웹훅 데이터 예시

[
  {
    "webhookIdx": 172,
    "webhookTargetIdx": 347066,
    "webhookTargetDataScheme": "TRANSACTION_1",
    "webhookTargetDataHash": "hiphZyBZ+jtKS4/XKiDAOagA7ex2S3Kg34+h1OqEAs8=",
    "data": {
      "memo": null,
      "txid": "0x46ac495ea3374510bb3dfd97cc28baa31526196cf19093bc62206779296979a6",
      "type": "DEPOSIT",
      "uuid": "ddb7d66e-dd67-4bef-8f68-fb70aab652db",
      "nonce": 45705,
      "amount": "0.10000000000000000000",
      "status": "FINALIZED",
      "symbol": "KLAY",
      "usedFee": "0.00077500000000000000",
      "toAddress": "0x01ac8A8624B44Ede413Dd3390f1E48A8d512bD2A",
      "failedDate": null,
      "blockHeight": "122645073",
      "createdDate": "2023-05-16T07:30:15.790Z",
      "fromAddress": "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4",
      "outputIndex": 0,
      "toAddresses": [
        "0x01ac8A8624B44Ede413Dd3390f1E48A8d512bD2A"
      ],
      "modifiedDate": "2023-05-16T07:30:26.000Z",
      "finalizedDate": "2023-05-16T07:30:26.000Z",
      "fromAddresses": [
        "0x55Bc4ba7A86A00C8A1A09C59DcC32eA2E7FAbCd4"
      ],
      "contractAddress": null,
      "feePayerAddress": "0x73b14def9a8b01525cb4eff356e01ce611d356aa",
      "unfinalizedDate": "2023-05-16T07:30:16.000Z",
      "useFeeDelegation": true,
      "transactionCurrency": {
        "krw": "226.99282922",
        "usd": "0.16965089"
      }
    }
  }
]