Skip to content

Commit

Permalink
rn 0.74. remove atob/btoa. remove textencoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
shamilovtim committed May 3, 2024
1 parent 6401a50 commit 247b623
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Don't use this package if:
| ------------------------------------- | ---------------------------------------------------------------------------------------- |
| `react-native-bignumber` | Supply `bn.js` with C++ instead of JS |
| `@craftzdog/react-native-buffer` | Supply node `Buffer` with C++ |
| `react-native-quick-base64` | Supply `global.atob` and `global.btoa` with C++ instead of JS |
| `react-native-blob-jsi-helper` | Supply `Blob` arrayBuffers with C++. |
| `blob-polyfill.ts` | Supply `Blob.stream()` with C++. Add Uint8Array support for `Blob.constructor()` with JS |
| `react-native-quick-crypto` | Supply the node `crypto` API with C++ OpenSSL |
Expand All @@ -36,15 +35,15 @@ Don't use this package if:
| `web-streams-polyfill` | Supply `ReadableStream` `WritableStream` with JS |
| `readable-stream` | Supply node `stream` with JS |
| `react-native-url-polyfill` | Supply the web & node `new URL()` API with JS |
| `fastestsmallesttextencoderdecoder` | Supply `new TextEncoder()` and `new TextDecoder()` with JS |
| `text-encoding` | Supply `new TextDecoder()` with JS |
| `@azure/core-asynciterator-polyfill ` | Supply `AsyncIterator` with JS |

## Usage

Install this package along with the following peer packages:

```
yarn add @tbd54566975/web5-react-native-polyfills react-native-quick-crypto@^0.7.0-rc.0 @craftzdog/react-native-buffer react-native-bignumber react-native-quick-base64 react-native-blob-jsi-helper
yarn add @tbd54566975/web5-react-native-polyfills react-native-quick-crypto@^0.7.0-rc.2 @craftzdog/react-native-buffer react-native-bignumber react-native-blob-jsi-helper
```

Add the following code to the top of your index.js entrypoint:
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"@noble/hashes": "^1.4.0",
"@peculiar/webcrypto": "^1.4.6",
"event-target-polyfill": "^0.0.4",
"fastestsmallesttextencoderdecoder": "^1.0.22",
"react-native-blob-jsi-helper": "^0.3.1",
"react-native-url-polyfill": "^2.0.0",
"readable-stream": "^4.5.2",
"realistic-structured-clone": "^3.0.0",
"text-encoding": "^0.7.0",
"web-streams-polyfill": "^4.0.0"
},
"peerDependencies": {
Expand All @@ -55,13 +55,17 @@
"@web5/dids": "*",
"react-native-bignumber": "*",
"react-native-blob-jsi-helper": "*",
"react-native-quick-base64": "*",
"react-native-quick-crypto": "*"
},
"peerDependenciesMeta": {
"react-native-bignumber": {
"optional": true
}
},
"devDependencies": {
"@types/react-native": "^0.73.0",
"prettier": "^3.2.5",
"release-it": "^17.2.0",
"release-it": "^17.2.1",
"typescript": "^5.3.3"
},
"release-it": {
Expand Down
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@ import { Crypto } from '@peculiar/webcrypto';
// not putting behind a check because this is the best and only tool for the job
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';

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

// js based TextDecoder
import { TextDecoder } from 'text-encoding';

// Hermes lacks AsyncIterator (fixed in upcoming versions)
// TODO: Remove when Hermes gets AsyncIterator
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');

// achachingbrain relying on the Event API in it-modules
if (typeof EventTarget === 'undefined') {
require('event-target-polyfill');
Expand All @@ -48,11 +43,10 @@ import { sha512 } from '@noble/hashes/sha512';
import * as secp from '@noble/secp256k1';
import * as ed from '@noble/ed25519';

global.TextDecoder = TextDecoder;
global.crypto = crypto;
global.crypto.subtle = new Crypto().subtle;
global.buffer = Buffer;
global.atob = atob;
global.btoa = btoa;

polyfillBlob();

Expand Down
42 changes: 20 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
integrity sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==

"@inquirer/figures@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@inquirer/figures/-/figures-1.0.1.tgz#d65f0bd0e9511a90b4d3543ee6a3ce7211f29417"
integrity sha512-mtup3wVKia3ZwULPHcbs4Mor8Voi+iIXEWD7wCNbIO6lYR62oPCTQyrddi5OMYVXHzeCSoneZwJuS8sBvlEwDw==

"@isaacs/ttlcache@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz#21fb23db34e9b6220c6ba023a0118a2dd3461ea2"
Expand Down Expand Up @@ -2799,11 +2804,6 @@ fast-xml-parser@^4.0.12, fast-xml-parser@^4.2.4:
dependencies:
strnum "^1.0.5"

fastestsmallesttextencoderdecoder@^1.0.22:
version "1.0.22"
resolved "https://registry.yarnpkg.com/fastestsmallesttextencoderdecoder/-/fastestsmallesttextencoderdecoder-1.0.22.tgz#59b47e7b965f45258629cc6c127bf783281c5e93"
integrity sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==

fastq@^1.6.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a"
Expand All @@ -2826,13 +2826,6 @@ fetch-blob@^3.1.2, fetch-blob@^3.1.4:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"

figures@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af"
integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==
dependencies:
escape-string-regexp "^1.0.5"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
Expand Down Expand Up @@ -3401,18 +3394,18 @@ ini@^1.3.4, ini@~1.3.0:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

inquirer@9.2.17:
version "9.2.17"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.2.17.tgz#87783875f2983cf8f64c30acb9c59cf044c71bc6"
integrity sha512-Vr3Ia2ud5sGnioURkE69endl4SkeJcMzTF6SosKcX5GALJfId7C+JvO5ZZb6y1LOXnEofCPbwzoQ1q0e8Gaduw==
inquirer@9.2.19:
version "9.2.19"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.2.19.tgz#e142ebc111b6328a21eb84d8e7dd226ff824239e"
integrity sha512-WpxOT71HGsFya6/mj5PUue0sWwbpbiPfAR+332zLj/siB0QA1PZM8v3GepegFV1Op189UxHUCF6y8AySdtOMVA==
dependencies:
"@inquirer/figures" "^1.0.1"
"@ljharb/through" "^2.3.13"
ansi-escapes "^4.3.2"
chalk "^5.3.0"
cli-cursor "^3.1.0"
cli-width "^4.1.0"
external-editor "^3.1.0"
figures "^3.2.0"
lodash "^4.17.21"
mute-stream "1.0.0"
ora "^5.4.1"
Expand Down Expand Up @@ -5310,10 +5303,10 @@ regjsparser@^0.9.1:
dependencies:
jsesc "~0.5.0"

release-it@^17.2.0:
version "17.2.0"
resolved "https://registry.yarnpkg.com/release-it/-/release-it-17.2.0.tgz#30b25364ec1bff247fe03e7fb76de51f988af667"
integrity sha512-Cidaq5W4apZSpdEDQd2TJhH7GZAwfaG+ewe60p7B7+txyCHYR/T6lGvkKinJmePpdHsM0fzA05yGGXKCiHJHmA==
release-it@^17.2.1:
version "17.2.1"
resolved "https://registry.yarnpkg.com/release-it/-/release-it-17.2.1.tgz#1d5bbc32023a79a819cf66807485126f19f127fd"
integrity sha512-zBOpaHyjrXC3g/9rHyQlvuDw9yCn9AGphrlL+t3gWNEhbZKEQ62WNY45JxllcJMNx9orQUxBZ3o7pVCqkeuTbg==
dependencies:
"@iarna/toml" "2.2.5"
"@octokit/rest" "20.1.0"
Expand All @@ -5324,7 +5317,7 @@ release-it@^17.2.0:
git-url-parse "14.0.0"
globby "14.0.1"
got "13.0.0"
inquirer "9.2.17"
inquirer "9.2.19"
is-ci "3.0.1"
issue-parser "7.0.0"
lodash "4.17.21"
Expand Down Expand Up @@ -5961,6 +5954,11 @@ terser@^5.15.0:
commander "^2.20.0"
source-map-support "~0.5.20"

text-encoding@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.7.0.tgz#f895e836e45990624086601798ea98e8f36ee643"
integrity sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==

throat@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/throat/-/throat-5.0.0.tgz#c5199235803aad18754a667d659b5e72ce16764b"
Expand Down

0 comments on commit 247b623

Please sign in to comment.