feat(init): shim `atob` and `btoa`
MODIFY
packages/base64/NEWS.md
packages/base64/NEWS.md
User-visible changes in base64:
+- Export `atob.js`, `btoa.js` for compatibility with the Web and Node.js APIs of
+ the same name. Also add `shim.js` to install them on `globalThis.atob` and
+ `globalThis.btoa` if they are missing.
+
# 0.2.8 (2021-09-18)
- Use native `Base64.encode` or `Base64.decode` if available in global scope.

MODIFY
packages/base64/index.js
packages/base64/index.js
export { encodeBase64 } from './src/encode.js';
export { decodeBase64 } from './src/decode.js';
+export { btoa } from './btoa.js';
+export { atob } from './atob.js';

MODIFY
packages/base64/package.json
packages/base64/package.json
"module": "./index.js",
"exports": {
".": "./index.js",
+ "./atob.js": "./atob.js",
+ "./btoa.js": "./btoa.js",
"./encode.js": "./encode.js",
"./decode.js": "./decode.js",
+ "./shim.js": "./shim.js",
"./package.json": "./package.json"
},
"scripts": {

ADD
packages/base64/shim.js
+/* global globalThis */
+// @ts-check
+import { atob } from './atob.js';
+import { btoa } from './btoa.js';
+
+if (globalThis.atob === undefined) {
+ globalThis.atob = atob;
+}
+
+if (globalThis.btoa === undefined) {
+ globalThis.btoa = btoa;
+}

MODIFY
packages/import-bundle/src/index.js
packages/import-bundle/src/index.js
@@ -27,6 +27,8 @@ export async function importBundle(bundle, options = {}) {
TextDecoder,
URL: globalThis.URL, // Absent only in XSnap
Base64: globalThis.Base64, // Present only in XSnap
+ atob: globalThis.atob,
+ btoa: globalThis.btoa,
...optEndowments,
};

MODIFY
packages/init/package.json
packages/init/package.json
},
"dependencies": {
"@endo/eventual-send": "^0.15.3",
+ "@endo/base64": "^0.2.25",
"@endo/lockdown": "^0.1.13"
},
"files": [

MODIFY
packages/init/pre.js
packages/init/pre.js
// Generic preamble for all shims.
+import '@endo/lockdown';
+import '@endo/base64/shim.js';
+
export * from '@endo/lockdown';

feat(init): shim `atob` and `btoa`