@capgo/capacitor-device-integrity

中文文档
8.0.15发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.1万

Device integrity and fraud signals for Capacitor using Android Widevine, Play Integrity, iOS App Attest, and DeviceCheck.

原始使用文档
文档目录19 节
  1. ➡️ Get started for free
  2. Key features
  3. Security model
  4. Compatibility
  5. Install
  6. Platform setup
  7. Android
  8. iOS
  9. Usage
  10. Backend handling
  11. API
  12. getCapabilities()
  13. getWidevineFingerprint(...)
  14. prepareAttestation(...)
  15. createAttestation(...)
  16. createAssertion(...)
  17. getDeviceCheckToken()
  18. Interfaces
  19. Type Aliases

@capgo/capacitor-device-integrity

Collect device integrity and fraud signals in your Capacitor app: Play Integrity and a Widevine fingerprint on Android, App Attest and DeviceCheck on iOS. Your backend can verify the attestation and DeviceCheck tokens and use the Widevine fingerprint as a risk signal.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-device-integrity in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-device-integrity to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-device-integrity for Capacitor apps

Key features

  • Attestation: prepareAttestation() prepares the native attestation state, then createAttestation() creates a token bound to a challenge from your backend.
  • Request assertions: createAssertion() signs a request payload for server-side checks.
  • Widevine fingerprint: getWidevineFingerprint() returns a stable Android DRM-derived ID.
  • DeviceCheck: getDeviceCheckToken() creates an iOS token for fraud-state lookups.
  • Capabilities: getCapabilities() reports what the current platform supports.
  • Platforms: iOS and Android. Not available on web.

Device integrity and fraud signals for Capacitor:

  • Android: Widevine DRM fingerprint and Play Integrity Standard API attestation.
  • iOS: Apple App Attest and DeviceCheck.
  • Web: unsupported fallback that reports no native capabilities.

Security model

This plugin is designed for fraud and abuse detection. It does not make client-side values trustworthy by itself.

  • Verify App Attest and Play Integrity tokens on your backend.
  • Treat Widevine values as sensitive identifiers.
  • Disclose identifier use in your privacy policy.
  • Do not use Android Widevine values for advertising or cross-app tracking.
  • Do not attempt iOS fingerprinting. Apple does not provide a public review-safe stable device ID for this use case.

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8..v8..Yes
v7..v7..On demand
v6..v6..On demand

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

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

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-device-integrity
npx cap sync

Platform setup

Android

Widevine fingerprinting does not require extra permissions.

Play Integrity requires Google Play services and a Cloud project number:

// capacitor.config.ts
plugins: {
  DeviceIntegrity: {
    cloudProjectNumber: '123456789012'
  }
}

You can also pass cloudProjectNumber directly to the attestation methods.

iOS

Enable the App Attest capability in Xcode:

  1. Open your app target.
  2. Go to Signing & Capabilities.
  3. Add App Attest.
  4. Test on a physical device when validating real App Attest and DeviceCheck behavior.

Usage

import { DeviceIntegrity } from '@capgo/capacitor-device-integrity';

const capabilities = await DeviceIntegrity.getCapabilities();

if (capabilities.platform === 'android' && capabilities.widevine.fingerprintAvailable) {
  const widevine = await DeviceIntegrity.getWidevineFingerprint();
  await api.saveDeviceSignal({
    widevineIdSha256: widevine.widevineIdSha256,
    fingerprint: widevine.fingerprint,
    securityLevel: widevine.securityLevel,
  });
}

if (capabilities.appAttest.supported || capabilities.playIntegrity.supported) {
  const prepared = await DeviceIntegrity.prepareAttestation();
  const challenge = await api.createDeviceChallenge();

  const attestation = await DeviceIntegrity.createAttestation({
    keyId: prepared.keyId,
    challenge,
  });

  await api.verifyDeviceAttestation(attestation);
}

if (capabilities.deviceCheck.supported) {
  const deviceCheck = await DeviceIntegrity.getDeviceCheckToken();
  await api.verifyDeviceCheckToken(deviceCheck.token);
}

Backend handling

Store the platform-specific evidence with the user record only after server-side checks:

  • Android Widevine: store widevineIdSha256 and optionally the raw widevineIdBase64 only when you explicitly need it.
  • Android Play Integrity: decode the returned token with Google's server API and validate request hash, package name, certificate digest, and device/app integrity verdicts.
  • iOS App Attest: verify the attestation object/assertion against Apple's App Attest rules, app identity, nonce, public key, and counter.
  • iOS DeviceCheck: send the token to Apple's DeviceCheck server API and maintain fraud bits on your backend.

API

getCapabilities()

getCapabilities() => Promise<DeviceIntegrityCapabilities>

Returns the native integrity capabilities available on the current platform.

Returns: Promise<DeviceIntegrityCapabilities>


getWidevineFingerprint(...)

getWidevineFingerprint(options?: WidevineFingerprintOptions | undefined) => Promise<WidevineFingerprintResult>

Returns an Android Widevine-derived fingerprint.

The default fingerprint is SHA-256 over the Widevine device unique ID and a salt. If hashSalt is not provided, Android uses the app package name as the salt.

The raw Widevine ID is sensitive and is only returned as base64 when includeRawId is true.

ParamType
optionsWidevineFingerprintOptions

Returns: Promise<WidevineFingerprintResult>


prepareAttestation(...)

prepareAttestation(options?: PrepareAttestationOptions | undefined) => Promise<PrepareAttestationResult>

Prepares native attestation state and returns the key/provider handle.

iOS: creates an App Attest key. Android: prepares a Play Integrity Standard token provider.

ParamType
optionsPrepareAttestationOptions

Returns: Promise<PrepareAttestationResult>


createAttestation(...)

createAttestation(options: CreateAttestationOptions) => Promise<AttestationTokenResult>

Creates a registration attestation token bound to a backend-issued challenge.

ParamType
optionsCreateAttestationOptions

Returns: Promise<AttestationTokenResult>


createAssertion(...)

createAssertion(options: CreateAssertionOptions) => Promise<AttestationTokenResult>

Creates a request assertion token bound to a request payload.

ParamType
optionsCreateAssertionOptions

Returns: Promise<AttestationTokenResult>


getDeviceCheckToken()

getDeviceCheckToken() => Promise<DeviceCheckTokenResult>

Creates an iOS DeviceCheck token for server-side fraud-state lookups.

Returns: Promise<DeviceCheckTokenResult>


Interfaces

DeviceIntegrityCapabilities

PropTypeDescription
platformDeviceIntegrityPlatformPlatform currently executing the plugin.
widevineWidevineCapabilitiesAndroid Widevine DRM support.
appAttestSupportStatusiOS App Attest support.
deviceCheckSupportStatusiOS DeviceCheck support.
playIntegritySupportStatusAndroid Play Integrity support.

WidevineCapabilities

PropTypeDescription
supportedbooleanWhether the Widevine DRM scheme is supported by the device.
fingerprintAvailablebooleanWhether the Widevine device unique ID can be read.
securityLevelScanSupportedbooleanWhether the Widevine security level property can be read.

SupportStatus

PropTypeDescription
supportedbooleanWhether the capability is available on the current device.

WidevineFingerprintResult

PropTypeDescription
platform'android'Always android.
source'widevine'Always widevine.
fingerprintstringSalted SHA-256 fingerprint for storing alongside a user record.
widevineIdSha256stringUnsalted SHA-256 hash of the Widevine device unique ID.
widevineIdBase64stringRaw Widevine device unique ID encoded as base64. Returned only when includeRawId is true.
securityLevelstringWidevine security level when available, for example L1 or L3.
vendorstringDRM vendor when available.
versionstringDRM plugin version when available.
descriptionstringDRM plugin description when available.

WidevineFingerprintOptions

PropTypeDescription
includeRawIdbooleanReturn the raw Widevine device unique ID as base64. Defaults to false.
hashSaltstringOptional salt used to derive fingerprint. Android uses the app package name when omitted.

PrepareAttestationResult

PropTypeDescription
keyIdstringiOS App Attest key ID or Android Play Integrity provider handle ID.
formatAttestationFormatNative attestation format used by the current platform.

PrepareAttestationOptions

PropTypeDescription
cloudProjectNumberstringAndroid only. Google Cloud project number for Play Integrity. Can be configured globally via plugins.DeviceIntegrity.cloudProjectNumber.

AttestationTokenResult

PropTypeDescription
tokenstringToken/assertion that must be verified server-side.
keyIdstringKey/provider handle used to create the token.
formatAttestationFormatNative attestation format used by the current platform.

CreateAttestationOptions

PropTypeDescription
keyIdstringKey/provider handle returned from prepareAttestation().
challengestringBackend-issued one-time challenge.
cloudProjectNumberstringAndroid only. Google Cloud project number for Play Integrity.

CreateAssertionOptions

PropTypeDescription
keyIdstringKey/provider handle returned from prepareAttestation().
payloadstringBackend-issued one-time request payload or nonce.
cloudProjectNumberstringAndroid only. Google Cloud project number for Play Integrity.

DeviceCheckTokenResult

PropTypeDescription
tokenstringiOS DeviceCheck token encoded as base64.

Type Aliases

DeviceIntegrityPlatform

'android' | 'ios' | 'web'

AttestationFormat

'apple-app-attest' | 'google-play-integrity-standard'

版本与发布记录

@capgo/capacitor-device-integrity 共发布 14 个版本,首次发布于 2026/06/04;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.15latest2026/10/1525 天前
8.0.142026/10/1327 天前
8.0.132026/10/091 个月前
8.0.122026/10/081 个月前
8.0.102026/10/081 个月前
8.0.112026/10/081 个月前

关于 @capgo/capacitor-device-integrity 的常见问题

@capgo/capacitor-device-integrity 是什么?

Device integrity and fraud signals for Capacitor using Android Widevine, Play Integrity, iOS App Attest, and DeviceCheck.

如何安装 @capgo/capacitor-device-integrity?

在项目目录运行 npm install @capgo/capacitor-device-integrity,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-device-integrity 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-device-integrity 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-device-integrity 可以商用吗?

@capgo/capacitor-device-integrity 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-device-integrity 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-device-integrity 在 2026/10/09 – 2026/11/07 这 30 天内被下载 41,026 次,日均约 1,368 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-device-integrity 还在维护吗?

最新版本 8.0.15 发布于 2026/10/15(25 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/06/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。