Skip to content

Commit

Permalink
format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
shamilovtim committed Apr 19, 2024
1 parent b15028c commit f79a0d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"prettier": {
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
}
7 changes: 4 additions & 3 deletions src/blob-polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getArrayBufferForBlob } from "react-native-blob-jsi-helper";
import { ReadableStream } from "web-streams-polyfill";
import { getArrayBufferForBlob } from 'react-native-blob-jsi-helper';
import { ReadableStream } from 'web-streams-polyfill';

const decoder = new TextDecoder();

Expand All @@ -24,7 +24,8 @@ function monkeyPatchBlobConstructor() {
// TODO #64: Investigate performance here, and see if we can make an upstream change to fix.
for (let i = 0; i < blobParts.length; i++) {
if (blobParts[i] instanceof Uint8Array) {
blobParts[i] = decoder.decode(blobParts[i]); // Decode and replace in place if the element is a Uint8Array
// Decode and replace in place if the element is a Uint8Array
blobParts[i] = decoder.decode(blobParts[i]);
}
}
}
Expand Down
40 changes: 19 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,51 @@

// C++ node crypto
// not putting behind a check because this is the best and only tool for the job
import crypto from "crypto";
import crypto from 'crypto';

// webcrypto fulfilled by C++ node crypto
// not putting behind a check because this is the best and only tool for the job
import { Crypto } from "@peculiar/webcrypto";
import { Crypto } from '@peculiar/webcrypto';

// ffi node buffer
// not putting behind a check because this is the best and only tool for the job
import { Buffer } from "buffer";
import { Buffer } from 'buffer';

// ffi base64
// not putting behind a check because this is the best and only tool for the job
import { atob, btoa } from "react-native-quick-base64";
import { atob, btoa } from 'react-native-quick-base64';

// add .stream() compatibility to blob
// add Uint8Array compatibility to blob constructor
import { polyfillBlob } from "./blob-polyfill";
import { polyfillBlob } from './blob-polyfill';

// Hermes lacks AsyncIterator (fixed in upcoming versions)
// TODO: Remove when Hermes gets AsyncIterator
if (typeof Symbol.asyncIterator === "undefined") {
require("@azure/core-asynciterator-polyfill");
if (typeof Symbol.asyncIterator === 'undefined') {
require('@azure/core-asynciterator-polyfill');
}

// js based TextEncoder TextDecoder (TextEncoder fixed in upcoming)
// there are checks inside the polyfill that will return the native impl if it exists
require("fastestsmallesttextencoderdecoder");
require('fastestsmallesttextencoderdecoder');

// achachingbrain relying on the Event API in it-modules
if (typeof EventTarget === "undefined") {
require("event-target-polyfill");
if (typeof EventTarget === 'undefined') {
require('event-target-polyfill');
}

// hermes lacks URL in old hermes versions (fixed in Expo)
if (typeof URL === "undefined") {
require("react-native-url-polyfill/auto");
}
// hermes lacks URL in old hermes versions (fixed in upcoming Expo)
require('react-native-url-polyfill/auto');

if (!global.structuredClone) {
global.structuredClone = require("realistic-structured-clone");
global.structuredClone = require('realistic-structured-clone');
}

import { hmac } from "@noble/hashes/hmac";
import { sha256 } from "@noble/hashes/sha256";
import { sha512 } from "@noble/hashes/sha512";
import * as secp from "@noble/secp256k1";
import * as ed from "@noble/ed25519";
import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha256';
import { sha512 } from '@noble/hashes/sha512';
import * as secp from '@noble/secp256k1';
import * as ed from '@noble/ed25519';

global.crypto = crypto;
global.crypto.subtle = new Crypto().subtle;
Expand All @@ -66,4 +64,4 @@ ed.etc.sha512Async = (...m) => Promise.resolve(ed.etc.sha512Sync(...m));
secp.etc.hmacSha256Sync = (k, ...m) =>
hmac(sha256, k, secp.etc.concatBytes(...m));
secp.etc.hmacSha256Async = (k, ...m) =>
Promise.resolve(secp.etc.hmacSha256Sync(k, ...m));
Promise.resolve(secp.etc.hmacSha256Sync(k, ...m));

0 comments on commit f79a0d5

Please sign in to comment.