スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-device-integrity`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/device-integrity/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」セクション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.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
-
パッケージをインストール
ターミナル bun add @capgo/capacitor-device-integrity -
ネイティブプロジェクトを同期
ターミナル bunx cap sync -
プラットフォーム要件の設定
- Android: 設定
plugins.DeviceIntegrity.cloudProjectNumberattestation API を使用する場合は、Play Integrity 用に設定します。 - iOS: attestation API 用に Xcode で App Attest 機能を有効にします。
- Android: 設定
クイックスタート
「クイックスタート」セクションimport { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const result = await DeviceIntegrity.getCapabilities();console.log(result);例: getWidevineFingerprint
セクション「例: getWidevineFingerprint」import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';
const capabilities = await DeviceIntegrity.getCapabilities();if (capabilities.widevine.fingerprintAvailable) { const result = await DeviceIntegrity.getWidevineFingerprint(); console.log(result);}例: prepareAttestation
セクション「例: prepareAttestation」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.tsGitHub リポジトリ内。
このプラグインを使う理由
「このプラグインを使用する理由」セクションサインアップ、ログイン、高リスク操作の際に、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);}Widevine オプション
「Widevine オプション」というセクションgetWidevineFingerprint() 以下のオプションフィールドを受け付けます:
| 項目 | 種類 | 説明 |
|---|---|---|
includeRawId | boolean | true の場合、base64 形式の raw Widevine デバイス ID(機密情報)を含めます。 |
hashSalt | string | 〜用のソルト 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 におけるプロダクトワークフロー向けに。