メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:

ターミナル
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用します:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-device-integrity` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

  1. パッケージをインストール

    ターミナル
    bun add @capgo/capacitor-device-integrity
  2. ネイティブプロジェクトを同期

    ターミナル
    bunx cap sync
  3. プラットフォーム要件の設定

    • Android: 設定 plugins.DeviceIntegrity.cloudProjectNumber attestation API を使用する場合は、Play Integrity 用に設定します。
    • iOS: attestation API 用に Xcode で App Attest 機能を有効にします。
import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const result = await DeviceIntegrity.getCapabilities();
console.log(result);
import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const capabilities = await DeviceIntegrity.getCapabilities();
if (capabilities.widevine.fingerprintAvailable) {
const result = await DeviceIntegrity.getWidevineFingerprint();
console.log(result);
}
import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const capabilities = await DeviceIntegrity.getCapabilities();
const attestationSupported =
capabilities.appAttest.supported || capabilities.playIntegrity.supported;
if (attestationSupported) {
const result = await DeviceIntegrity.prepareAttestation();
console.log(result);
}
  • ネイティブ同期: 実行 npx cap sync プラグインのアップグレード後。
  • 信頼できる情報源: 信頼 src/definitions.ts GitHub リポジトリ内。

サインアップ、ログイン、高リスク操作の際に、1 つの API で整合性シグナルを収集します:

  • ネイティブ API を呼び出す前に、サポート状況を確認する (getCapabilities)
  • Widevine で Android デバイスをフィンガープリントする (getWidevineFingerprint)
  • App Attest または Play Integrity で登録とアサートを行う (prepareAttestation, createAttestation, createAssertion)
  • iOS DeviceCheck トークンをリクエストする (getDeviceCheckToken)

バックエンドでトークンを検証し、リプレイ攻撃対策を適用するまで、クライアント側の値は信頼できません。

import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const capabilities = await DeviceIntegrity.getCapabilities();
console.log(capabilities.platform, capabilities.playIntegrity.supported);
if (capabilities.widevine.fingerprintAvailable) {
const widevine = await DeviceIntegrity.getWidevineFingerprint();
console.log(widevine.fingerprint, widevine.securityLevel);
}
const attestationSupported =
capabilities.appAttest.supported || capabilities.playIntegrity.supported;
if (attestationSupported) {
try {
const prepared = await DeviceIntegrity.prepareAttestation();
const challengeResponse = await fetch(
'https://api.example.com/integrity/registration-challenge',
);
if (!challengeResponse.ok) {
throw new Error(`Challenge request failed with ${challengeResponse.status}`);
}
const challengeBody = await challengeResponse.json();
if (typeof challengeBody.challenge !== 'string' || challengeBody.challenge.length === 0) {
throw new Error('Backend response missing challenge');
}
const challenge = challengeBody.challenge;
const registration = await DeviceIntegrity.createAttestation({
keyId: prepared.keyId,
challenge,
});
const payloadResponse = await fetch(
'https://api.example.com/integrity/assertion-payload',
);
if (!payloadResponse.ok) {
throw new Error(`Payload request failed with ${payloadResponse.status}`);
}
const payloadBody = await payloadResponse.json();
if (typeof payloadBody.payload !== 'string' || payloadBody.payload.length === 0) {
throw new Error('Backend response missing payload');
}
const payload = payloadBody.payload;
const assertion = await DeviceIntegrity.createAssertion({
keyId: prepared.keyId,
payload,
});
console.log(registration.format, registration.token);
console.log(assertion.format, assertion.token);
} catch (error) {
console.error('Attestation flow failed', error);
}
}
if (capabilities.deviceCheck.supported) {
const deviceCheck = await DeviceIntegrity.getDeviceCheckToken();
console.log(deviceCheck.token);
}

getWidevineFingerprint() 以下のオプションフィールドを受け付けます:

項目種類説明
includeRawIdbooleantrue の場合、base64 形式の raw Widevine デバイス ID(機密情報)を含めます。
hashSaltstring〜用のソルト fingerprint。省略した場合、Android ではアプリのパッケージ名が使用されます。
  • サーバー上で App Attest と Play Integrity トークンを検証します。
  • Widevine 識別子を機密情報として扱い、プライバシーポリシーにその利用を明記してください。
  • Widevine の値を広告やアプリ間トラッキングに使用しないでください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド セキュリティとコンプライアンスを計画するには、これを以下と連携させてください @capgo/capacitor-device-integrity の使い方 「@capgo/capacitor-device-integrity の使い方」のネイティブ機能については、 @capgo/capacitor-app-attest App Attest と Play Integrity に特化したフロー向けの 暗号化 暗号化の実装詳細について コンプライアンス Compliance の実装の詳細については、また Capgo のセキュリティ Capgo Security におけるプロダクトワークフロー向けに。