Skip to content

Commit

Permalink
fix: append recivers broken (#5075)
Browse files Browse the repository at this point in the history
* fix: append recivers broken

* fix: lockfile
  • Loading branch information
Jack-Works committed Dec 7, 2021
1 parent be4e4cd commit 7bf678f
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 172 deletions.
11 changes: 7 additions & 4 deletions packages/mask/.webpack/config.ts
Expand Up @@ -275,7 +275,7 @@ export function createConfiguration(rawFlags: BuildFlags): Configuration {
} else {
entries.background = normalizeEntryDescription(join(__dirname, '../src/background-service.ts'))
plugins.push(new WebExtensionPlugin({ background: { entry: 'background', manifest: 2 } }))
plugins.push(addHTMLEntry({ chunks: ['background'], filename: 'background.html' }))
plugins.push(addHTMLEntry({ chunks: ['background'], filename: 'background.html', secp256k1: true }))
}
for (const entry in entries) {
withReactDevTools(entries[entry])
Expand All @@ -297,10 +297,13 @@ export function createConfiguration(rawFlags: BuildFlags): Configuration {
}
}
}
function addHTMLEntry(options: HTMLPlugin.Options = {}) {
function addHTMLEntry(options: HTMLPlugin.Options & { secp256k1?: boolean } = {}) {
let templateContent = readFileSync(join(__dirname, './template.html'), 'utf8')
if (options.chunks?.includes('background')) {
templateContent.replace(`<!-- background -->`, '<script src="/polyfill/secp256k1.js"></script>')
if (options.secp256k1) {
templateContent = templateContent.replace(
`<!-- secp256k1 -->`,
'<script src="/polyfill/secp256k1.js"></script>',
)
}
return new HTMLPlugin({
templateContent,
Expand Down
3 changes: 1 addition & 2 deletions packages/mask/.webpack/template.html
Expand Up @@ -5,9 +5,8 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<script src="/patches.js"></script>
<!-- background -->
<!-- secp256k1 -->
<script src="/polyfill/ecmascript.js"></script>
<script src="/polyfill/esnext.js"></script>
<script src="/polyfill/intl.js"></script>
<script src="/polyfill/dom.js"></script>
<script src="/polyfill/browser-polyfill.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion packages/mask/background/database/utils/openDB.ts
Expand Up @@ -31,7 +31,8 @@ export function createDBAccess<DBSchema>(opener: () => Promise<IDBPDatabase<DBSc
if (db) {
try {
// try if the db still open
db.transaction([], 'readonly', {})
const t = db.transaction([db.objectStoreNames[0]], 'readonly', {})
t.commit()
return db
} catch {
clean()
Expand Down
1 change: 0 additions & 1 deletion packages/mask/package.json
Expand Up @@ -121,7 +121,6 @@
"web3-eth-abi": "1.5.2",
"web3-eth-contract": "1.5.2",
"web3-utils": "1.5.2",
"webcrypto-liner": "1.2.4",
"webextension-polyfill": "^0.8.0",
"z-schema": "^5.0.2",
"zod": "3.11.6"
Expand Down
Expand Up @@ -10,7 +10,6 @@ import {
MnemonicGenerationInformation,
} from '../../../utils/mnemonic-code'
import type { MnemonicWordDetail } from '../interfaces/interface.blockchain'
import 'webcrypto-liner'

const ECDH = getKeyParameter('ecdh')[0]
const ECDSA = getKeyParameter('ecdsa')[0]
Expand Down
5 changes: 2 additions & 3 deletions packages/polyfills/builder.mjs
Expand Up @@ -20,7 +20,7 @@ let polyfillVersion = '__'
const lockfile = await readFile(lockfilePath)
const hash = createHash('sha256')
hash.update(lockfile)
polyfillVersion = 'v1' + hash.digest('hex')
polyfillVersion = 'v2' + hash.digest('hex')
}

const versionFilePath = fileURLToPath(new URL('./dist/version.txt', import.meta.url))
Expand Down Expand Up @@ -57,8 +57,7 @@ const liner = await readFile(require.resolve('webcrypto-liner/build/webcrypto-li
await writeFile(
fileURLToPath(new URL(`./dist/secp256k1.js`, import.meta.url)),
`${elliptic};
${liner};
delete globalThis.elliptic;`,
${liner};`,
)

await appendNull(new URL('./dist/dom.js', import.meta.url))
Expand Down
3 changes: 2 additions & 1 deletion packages/polyfills/elliptic.js
@@ -1,3 +1,4 @@
import elliptic from 'elliptic'
// @ts-ignore
import { Buffer } from './node_modules/buffer/index'
globalThis.elliptic = elliptic
globalThis.Buffer = Buffer
1 change: 1 addition & 0 deletions packages/polyfills/package.json
Expand Up @@ -16,6 +16,7 @@
"build": "node ./builder.mjs"
},
"dependencies": {
"buffer": "^6.0.3",
"clipboard-polyfill": "^3.0.3",
"core-js": "^3.19.1",
"elliptic": "^6.5.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/polyfills/rollup.config.js
Expand Up @@ -56,6 +56,6 @@ function plugins() {
exclude: ['node_modules/**'],
transforms: ['typescript'],
}),
terser(),
terser({ mangle: false }),
]
}

0 comments on commit 7bf678f

Please sign in to comment.