npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-ios-appattest

v1.0.1

Published

Native module for React Native that wraps iOS App Attest APIs

Downloads

126

Readme

react-native-ios-appattest

This library for React Native wraps Native iOS App Attest API's. AppAttest API's can be used by an app to prove its integrity to backends. Apple's documentation can be found here.

Related repos:

Consuming the library

$ npm install react-native-ios-appattest --save
// Link native components
$ cd ios && pod install && cd ..

In case you have build time issues with Flipper, disable Flipper while linking native components.

NO_FLIPPER=1 pod install

Note Attestation is only supported on real devices, not on simulators.

Generating an Attestation to provide device integrity

import * as AppAttest from 'react-native-ios-appattest';

// First ensure the device supports attestation
const supported = await AppAttest.attestationSupported();
if (!supported) { /* handle accordingly */ }

// Generate key-pair in Secure-enclave.
const keyId = await AppAttest.generateKeys();

// Fetch a challenge/nonce from server.
const challengeHashBase64 = // compute SHA256 of challenge & get base64 of hash.

// Ask Apple to attest keys.
const attestationBase64 = await AppAttest.attestKeys(
  keyId,
  challengeHashBase64,
);

Send attestationBase64 to your server. The server needs to check the attestation object (and you can use appattest-checker-node). If the checks pass, save the public key for the client (which is embedded in the attestation) in the server, indexed by some id for this device.

If the server confirms that attestationBase64 could be validated, client should persist keyId string for use with request attestation.

Attesting Requests

When the client needs to issue requests to the backend, it can generate assertions for them, such that the backend can trust their integrity (e.g. they came from the same device and haven't been tampered with)


// Get challenge / nonce from the server.
const serverChallenge = <...>

// Compute body of high-value request and include challenge in it.
const requestBody = { /*...other stuff ...*/, challenge: serverChallenge };
const clientDataHashBase64 = // Compute SHA256 of requestBody & base64 of hash
// Note that when computing the hash, ensure a consistent representation of the
// body is used. E.g. json-stable-stringify can be used to generate a
// consistent string representation, before computing SHA256.

// Generate an attestation for the request using keyId generated earlier
const clientAttestationBase64 = await AppAttest.attestRequestData(
  clientDataHashBase64,
  this.keyId,
);

Send the request to the backend as normal and include clientAttestationBase64 (e.g. as an HTTP header). The server should needs to validate the attestation before executing the request. It should use the previously saved public key for the client. The request should be executed only if it the attestation passes validation. appattest-checker-node provides an API to do this.