Skip to content

Commit b87d70c

Browse files
author
kkosiorowska
authored
Merge branch 'main' into release-0.41.0
2 parents 2ca5ce3 + a39b9b4 commit b87d70c

File tree

145 files changed

+6826
-2849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+6826
-2849
lines changed

.env.defaults

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ SUPPORT_SWAP_QUOTE_REFRESH=false
3232
SUPPORT_ACHIEVEMENTS_BANNER=false
3333
SUPPORT_NFT_SEND=false
3434
USE_MAINNET_FORK=false
35-
ENABLE_UPDATED_DAPP_CONNECTIONS=false
35+
ENABLE_UPDATED_DAPP_CONNECTIONS=true

.eslintrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ module.exports = {
9292
],
9393
},
9494
],
95-
"@typescript-eslint/no-unused-vars": "error",
95+
"@typescript-eslint/no-unused-vars": [
96+
"error",
97+
{
98+
argsIgnorePattern: "^_",
99+
varsIgnorePattern: "^_",
100+
},
101+
],
96102
"no-unused-vars": "off",
97103
},
98104
ignorePatterns: [

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Any changes to keyring code deserve extra scrutiny to prevent key
1+
# Any changes to internal-signer service code deserve extra scrutiny to prevent key
22
# exfiltration and general "roll your own crypto" mistakes. Newer
3-
# contributions to keyring code should be assumed insecure, requiring
3+
# contributions to internal-signer code should be assumed insecure, requiring
44
# agreement across the team to merge.
5-
/background/services/keyring/* @tahowallet/extension-security-auditors
5+
/background/services/internal-signer/* @tahowallet/extension-security-auditors
66
# Any changes to dependencies deserve extra scrutiny to help prevent supply
77
# chain attacks
88
yarn.lock @tahowallet/extension-dependency-auditors

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ services (in the API package) and the interface and browser notifications:
243243
│ │ - On-chain prices ┃ │ └─────────────────┘
244244
│ │ ┃ │
245245
│ │ ┃ │ ┌────────────────┐
246-
│ │ Keyring ┃ │ │ │
246+
│ │ Internal Signer ┃ │ │ │
247247
│ ├──────list accounts, sign tx, sign message───────▶ - Native ────────────────╋─────┼──────▶ Extension │
248248
│ │ - Remote ┃ │ │ Storage API │
249249
│ ┌──────────┴──────────┐ ┃ │ │ │

background/lib/posthog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export enum AnalyticsEvent {
1212
NEW_ACCOUNT_TO_TRACK = "Address added to tracking on network",
1313
CUSTOM_CHAIN_ADDED = "Custom chain added",
1414
DAPP_CONNECTED = "Dapp Connected",
15+
VAULT_MIGRATION = "Migrate to newer vault version",
16+
VAULT_MIGRATION_FAILED = "Vault version migration failed",
1517
}
1618

1719
export enum OneTimeAnalyticsEvent {

background/lib/token-lists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { DeepWriteable } from "../types"
2222
const cleanTokenListResponse = (json: any, url: string) => {
2323
if (url.includes("api-polygon-tokens.polygon.technology")) {
2424
if (typeof json === "object" && json !== null && "tags" in json) {
25-
const { tags, ...cleanedJson } = json
25+
const { tags: _, ...cleanedJson } = json
2626
return cleanedJson
2727
}
2828
}

background/lib/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ export function gweiToWei(value: number | bigint): bigint {
108108
return BigInt(utils.parseUnits(value.toString(), "gwei").toString())
109109
}
110110

111-
export function convertToEth(value: string | number | bigint): string {
111+
export function convertToEth(value: bigint): string {
112112
if (value && value >= 1) {
113113
return utils.formatUnits(BigInt(value))
114114
}
115115
return ""
116116
}
117117

118-
export function weiToGwei(value: string | number | bigint): string {
118+
export function weiToGwei(value: bigint): string {
119119
if (value && value >= 1) {
120120
return truncateDecimalAmount(utils.formatUnits(BigInt(value), "gwei"), 2)
121121
}

background/lib/validate/prices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const coingeckoPriceSchema: JSONSchemaType<CoingeckoPriceData> = {
2727
additionalProperties: { type: "number", nullable: true },
2828
nullable: true,
2929
},
30-
}
30+
} as const
3131

3232
export type CoingeckoPriceData = {
3333
[coinId: string]:

background/main.ts

Lines changed: 73 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
EnrichmentService,
2424
IndexingService,
2525
InternalEthereumProviderService,
26-
KeyringService,
26+
InternalSignerService,
2727
NameService,
2828
PreferenceService,
2929
ProviderBridgeService,
@@ -38,7 +38,7 @@ import {
3838
getNoopService,
3939
} from "./services"
4040

41-
import { HexString, KeyringTypes, NormalizedEVMAddress } from "./types"
41+
import { HexString, NormalizedEVMAddress } from "./types"
4242
import { SignedTransaction } from "./networks"
4343
import { AccountBalance, AddressOnNetwork, NameOnNetwork } from "./accounts"
4444
import { Eligible } from "./services/doggo/types"
@@ -65,12 +65,12 @@ import {
6565
setReferrerStats,
6666
} from "./redux-slices/claim"
6767
import {
68-
emitter as keyringSliceEmitter,
69-
keyringLocked,
70-
keyringUnlocked,
71-
updateKeyrings,
68+
emitter as internalSignerSliceEmitter,
69+
internalSignerLocked,
70+
internalSignerUnlocked,
71+
updateInternalSigners,
7272
setKeyringToVerify,
73-
} from "./redux-slices/keyrings"
73+
} from "./redux-slices/internal-signer"
7474
import { blockSeen, setEVMNetworks } from "./redux-slices/networks"
7575
import {
7676
initializationLoadingTimeHitLimit,
@@ -83,6 +83,7 @@ import {
8383
toggleCollectAnalytics,
8484
setShowAnalyticsNotification,
8585
setSelectedNetwork,
86+
setAutoLockInterval,
8687
setShownDismissableItems,
8788
dismissableItemMarkedAsShown,
8889
} from "./redux-slices/ui"
@@ -191,6 +192,10 @@ import {
191192
isBuiltInNetworkBaseAsset,
192193
isSameAsset,
193194
} from "./redux-slices/utils/asset-utils"
195+
import {
196+
SignerImportMetadata,
197+
SignerInternalTypes,
198+
} from "./services/internal-signer"
194199
import { getPricePoint, getTokenPrices } from "./lib/prices"
195200
import { DismissableItem } from "./services/preferences"
196201

@@ -298,8 +303,16 @@ export default class Main extends BaseService<never> {
298303

299304
static create: ServiceCreatorFunction<never, Main, []> = async () => {
300305
const preferenceService = PreferenceService.create()
301-
const keyringService = KeyringService.create()
302-
const chainService = ChainService.create(preferenceService, keyringService)
306+
const analyticsService = AnalyticsService.create(preferenceService)
307+
308+
const internalSignerService = InternalSignerService.create(
309+
preferenceService,
310+
analyticsService
311+
)
312+
const chainService = ChainService.create(
313+
preferenceService,
314+
internalSignerService
315+
)
303316
const indexingService = IndexingService.create(
304317
preferenceService,
305318
chainService
@@ -323,13 +336,11 @@ export default class Main extends BaseService<never> {
323336
const ledgerService = LedgerService.create()
324337

325338
const signingService = SigningService.create(
326-
keyringService,
339+
internalSignerService,
327340
ledgerService,
328341
chainService
329342
)
330343

331-
const analyticsService = AnalyticsService.create(preferenceService)
332-
333344
const nftsService = NFTsService.create(chainService)
334345

335346
const abilitiesService = AbilitiesService.create(
@@ -380,7 +391,7 @@ export default class Main extends BaseService<never> {
380391
await chainService,
381392
await enrichmentService,
382393
await indexingService,
383-
await keyringService,
394+
await internalSignerService,
384395
await nameService,
385396
await internalEthereumProviderService,
386397
await providerBridgeService,
@@ -418,11 +429,11 @@ export default class Main extends BaseService<never> {
418429
*/
419430
private indexingService: IndexingService,
420431
/**
421-
* A promise to the keyring service, which stores key material, derives
422-
* accounts, and signs messagees and transactions. The promise will be
432+
* A promise to the internal signer service, which stores key material, derives
433+
* accounts, and signs messages and transactions. The promise will be
423434
* resolved when the service is initialized.
424435
*/
425-
private keyringService: KeyringService,
436+
private internalSignerService: InternalSignerService,
426437
/**
427438
* A promise to the name service, responsible for resolving names to
428439
* addresses and content.
@@ -533,7 +544,7 @@ export default class Main extends BaseService<never> {
533544
this.chainService.startService(),
534545
this.indexingService.startService(),
535546
this.enrichmentService.startService(),
536-
this.keyringService.startService(),
547+
this.internalSignerService.startService(),
537548
this.nameService.startService(),
538549
this.internalEthereumProviderService.startService(),
539550
this.providerBridgeService.startService(),
@@ -556,7 +567,7 @@ export default class Main extends BaseService<never> {
556567
this.chainService.stopService(),
557568
this.indexingService.stopService(),
558569
this.enrichmentService.stopService(),
559-
this.keyringService.stopService(),
570+
this.internalSignerService.stopService(),
560571
this.nameService.stopService(),
561572
this.internalEthereumProviderService.stopService(),
562573
this.providerBridgeService.stopService(),
@@ -576,7 +587,7 @@ export default class Main extends BaseService<never> {
576587

577588
async initializeRedux(): Promise<void> {
578589
this.connectIndexingService()
579-
this.connectKeyringService()
590+
this.connectInternalSignerService()
580591
this.connectNameService()
581592
this.connectInternalEthereumProviderService()
582593
this.connectProviderBridgeService()
@@ -1071,7 +1082,7 @@ export default class Main extends BaseService<never> {
10711082
}
10721083

10731084
async connectSigningService(): Promise<void> {
1074-
this.keyringService.emitter.on("address", (address) =>
1085+
this.internalSignerService.emitter.on("address", (address) =>
10751086
this.signingService.addTrackedAddress(address, "keyring")
10761087
)
10771088

@@ -1110,12 +1121,12 @@ export default class Main extends BaseService<never> {
11101121
})
11111122
}
11121123

1113-
async connectKeyringService(): Promise<void> {
1114-
this.keyringService.emitter.on("keyrings", (keyrings) => {
1115-
this.store.dispatch(updateKeyrings(keyrings))
1124+
async connectInternalSignerService(): Promise<void> {
1125+
this.internalSignerService.emitter.on("internalSigners", (signers) => {
1126+
this.store.dispatch(updateInternalSigners(signers))
11161127
})
11171128

1118-
this.keyringService.emitter.on("address", async (address) => {
1129+
this.internalSignerService.emitter.on("address", async (address) => {
11191130
const trackedNetworks = await this.chainService.getTrackedNetworks()
11201131
trackedNetworks.forEach((network) => {
11211132
// Mark as loading and wire things up.
@@ -1134,48 +1145,41 @@ export default class Main extends BaseService<never> {
11341145
})
11351146
})
11361147

1137-
this.keyringService.emitter.on("locked", async (isLocked) => {
1148+
this.internalSignerService.emitter.on("locked", async (isLocked) => {
11381149
if (isLocked) {
1139-
this.store.dispatch(keyringLocked())
1150+
this.store.dispatch(internalSignerLocked())
11401151
} else {
1141-
this.store.dispatch(keyringUnlocked())
1152+
this.store.dispatch(internalSignerUnlocked())
11421153
}
11431154
})
11441155

1145-
keyringSliceEmitter.on("createPassword", async (password) => {
1146-
await this.keyringService.unlock(password, true)
1156+
internalSignerSliceEmitter.on("createPassword", async (password) => {
1157+
await this.internalSignerService.unlock(password, true)
11471158
})
11481159

1149-
keyringSliceEmitter.on("lockKeyrings", async () => {
1150-
await this.keyringService.lock()
1160+
internalSignerSliceEmitter.on("lockInternalSigners", async () => {
1161+
await this.internalSignerService.lock()
11511162
})
11521163

1153-
keyringSliceEmitter.on("deriveAddress", async (keyringID) => {
1164+
internalSignerSliceEmitter.on("deriveAddress", async (keyringID) => {
11541165
await this.signingService.deriveAddress({
11551166
type: "keyring",
11561167
keyringID,
11571168
})
11581169
})
11591170

1160-
keyringSliceEmitter.on("generateNewKeyring", async (path) => {
1171+
internalSignerSliceEmitter.on("generateNewKeyring", async (path) => {
11611172
// TODO move unlocking to a reasonable place in the initialization flow
11621173
const generated: {
11631174
id: string
11641175
mnemonic: string[]
1165-
} = await this.keyringService.generateNewKeyring(
1166-
KeyringTypes.mnemonicBIP39S256,
1176+
} = await this.internalSignerService.generateNewKeyring(
1177+
SignerInternalTypes.mnemonicBIP39S256,
11671178
path
11681179
)
11691180

11701181
this.store.dispatch(setKeyringToVerify(generated))
11711182
})
1172-
1173-
keyringSliceEmitter.on(
1174-
"importKeyring",
1175-
async ({ mnemonic, path, source }) => {
1176-
await this.keyringService.importKeyring(mnemonic, source, path)
1177-
}
1178-
)
11791183
}
11801184

11811185
async connectInternalEthereumProviderService(): Promise<void> {
@@ -1502,6 +1506,14 @@ export default class Main extends BaseService<never> {
15021506
}
15031507
)
15041508

1509+
this.preferenceService.emitter.on(
1510+
"updateAutoLockInterval",
1511+
async (newTimerValue) => {
1512+
await this.internalSignerService.updateAutoLockInterval()
1513+
this.store.dispatch(setAutoLockInterval(newTimerValue))
1514+
}
1515+
)
1516+
15051517
this.preferenceService.emitter.on(
15061518
"initializeShownDismissableItems",
15071519
async (dismissableItems) => {
@@ -1670,8 +1682,20 @@ export default class Main extends BaseService<never> {
16701682
})
16711683
}
16721684

1673-
async unlockKeyrings(password: string): Promise<boolean> {
1674-
return this.keyringService.unlock(password)
1685+
async unlockInternalSigners(password: string): Promise<boolean> {
1686+
return this.internalSignerService.unlock(password)
1687+
}
1688+
1689+
async exportMnemonic(address: HexString): Promise<string | null> {
1690+
return this.internalSignerService.exportMnemonic(address)
1691+
}
1692+
1693+
async exportPrivateKey(address: HexString): Promise<string | null> {
1694+
return this.internalSignerService.exportPrivateKey(address)
1695+
}
1696+
1697+
async importSigner(signerRaw: SignerImportMetadata): Promise<string | null> {
1698+
return this.internalSignerService.importSigner(signerRaw)
16751699
}
16761700

16771701
async getActivityDetails(txHash: string): Promise<ActivityDetail[]> {
@@ -1713,7 +1737,7 @@ export default class Main extends BaseService<never> {
17131737
This event is fired when any address on a network is added to the tracked list.
17141738
17151739
Note: this does not track recovery phrase(ish) import! But when an address is used
1716-
on a network for the first time (read-only or recovery phrase/ledger/keyring).
1740+
on a network for the first time (read-only or recovery phrase/ledger/keyring/private key).
17171741
`,
17181742
}
17191743
)
@@ -1773,6 +1797,10 @@ export default class Main extends BaseService<never> {
17731797
this.analyticsService.sendAnalyticsEvent(event)
17741798
}
17751799
})
1800+
1801+
uiSliceEmitter.on("updateAutoLockInterval", async (newTimerValue) => {
1802+
await this.preferenceService.updateAutoLockInterval(newTimerValue)
1803+
})
17761804
}
17771805

17781806
async updateAssetMetadata(

background/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@ledgerhq/hw-transport": "^6.20.0",
4040
"@ledgerhq/hw-transport-webusb": "^6.20.0",
4141
"@redux-devtools/remote": "^0.7.4",
42-
"@tallyho/hd-keyring": "0.4.0",
42+
"@tallyho/hd-keyring": "0.5.0",
4343
"@tallyho/provider-bridge-shared": "0.0.1",
4444
"@tallyho/window-provider": "0.0.1",
4545
"@types/w3c-web-usb": "^1.0.5",
@@ -49,7 +49,9 @@
4949
"@walletconnect/utils": "^2.1.4",
5050
"ajv": "^8.6.2",
5151
"ajv-formats": "^2.1.0",
52+
"argon2-browser": "^1.18.0",
5253
"assert": "^2.0.0",
54+
"base64-loader": "^1.0.0",
5355
"bnc-sdk": "^3.4.1",
5456
"dayjs": "^1.10.7",
5557
"dexie": "^3.0.3",
@@ -64,6 +66,7 @@
6466
},
6567
"devDependencies": {
6668
"@reduxjs/toolkit": "^1.6.1",
69+
"@types/argon2-browser": "^1.18.1",
6770
"@types/sinon": "^10.0.12",
6871
"@types/uuid": "^8.3.4",
6972
"@types/webextension-polyfill": "^0.8.0",

0 commit comments

Comments
 (0)