I'm trying to connect to the app store API in my react native app, but anytime I try to import a JWT pacakge to sign the token, I get a package error. Here is my code and the error I get
import * as JSW from 'jose'; //json web token signer
export default class appStoreAPI {
private static _instance:appStoreAPI;
static get I() {
if(!this._instance) this._instance = new appStoreAPI();
return this._instance;
}
token_creations = () => {
const credentials = {
privateKey: 'my private key',
apiKeyId: 'api from app store',
issuerId: 'issuer id from app store'
}
let now = Math.round((new Date().getTime()/1000));
let nowPlus20 = now + 1999
let token = {
header: {
"alg":"ES256",
"kid": credentials.apiKeyId,
"typ": "JWT"
},
payload: {
"iss": credentials.issuerId,
"iat": now,
"exp": nowPlus20,
"aud": "appstoreconnect-v1",
"scope": [
"GET /v1/apps?filter[platform]=IOS"
]
},
}
const token_sign = new JSW.SignJWT(token)
}
}
And I get this error:
ReferenceError: Can't find variable: crypto
I've npm installed crypto already
If I comment out the JWT import, then this error goes away. I am also using expo. Not sure if I'm signing this token correctly either.
jose
's own readme does not mention react-native as a supported runtime. react-native is missing (and not planning for) a Web Cryptography API implementationIt's a shame because it is a sought after runtime for
jose
, but without the runtime having a basic set of interoperable Web APIs there's nothing much I can do to support it.