-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
172 additions
and
130 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
holo-key-manager-extension/build-scripts/fixBackgroundScriptForSigning.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
// replaceForFirefox.cjs | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const backgroundScriptPath = path.resolve(__dirname, '../build/scripts/background.js'); | ||
|
||
fs.readFile(backgroundScriptPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error('Error reading the background script file:', err); | ||
return; | ||
} | ||
|
||
let modifiedData = data.replace(/global\./g, 'self.'); | ||
|
||
modifiedData = modifiedData.replace( | ||
/var normalize = bufferUtil\.normalize;/g, | ||
`var normalize = function (buffer) { | ||
if (Buffer.isBuffer(buffer)) return buffer; | ||
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength); | ||
};` | ||
); | ||
|
||
fs.writeFile(backgroundScriptPath, modifiedData, 'utf8', (err) => { | ||
if (err) { | ||
console.error('Error writing the modified background script file:', err); | ||
return; | ||
} | ||
|
||
console.log('Background script file modified successfully.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { AUTHENTICATED_APPS_LIST, SESSION } from '@shared/const'; | ||
import { base64ToUint8Array, uint8ArrayToBase64 } from '@shared/helpers'; | ||
import { getSessionKey, storageService } from '@shared/services'; | ||
import { | ||
AuthenticatedAppsListSchema, | ||
type MessageToSign, | ||
SuccessMessageSignedSchema | ||
} from '@shared/types'; | ||
// @ts-expect-error no types for hcSeedBundle | ||
import * as hcSeedBundle from 'hcSeedBundle'; | ||
|
||
export const signMessageLogic = async ({ message, happId }: MessageToSign) => { | ||
const authenticatedAppsListData = await storageService.getWithoutCallback({ | ||
key: AUTHENTICATED_APPS_LIST, | ||
area: SESSION | ||
}); | ||
|
||
const parsedAuthenticatedAppsListData = | ||
AuthenticatedAppsListSchema.safeParse(authenticatedAppsListData); | ||
|
||
if (!parsedAuthenticatedAppsListData.success) { | ||
throw new Error('Failed to parse authenticated apps list data'); | ||
} | ||
|
||
const index = parsedAuthenticatedAppsListData.data[happId]; | ||
const sessionKey = await getSessionKey(); | ||
|
||
if (!sessionKey.success) { | ||
throw new Error('Session data not found'); | ||
} | ||
|
||
await hcSeedBundle.seedBundleReady; | ||
|
||
const cipherList = hcSeedBundle.UnlockedSeedBundle.fromLocked( | ||
base64ToUint8Array(sessionKey.data) | ||
); | ||
|
||
if (!(cipherList[0] instanceof hcSeedBundle.LockedSeedCipherPwHash)) { | ||
throw new Error('Expecting PwHash'); | ||
} | ||
|
||
const pw = new TextEncoder().encode(SESSION); | ||
const keyUnlocked = cipherList[0].unlock(hcSeedBundle.parseSecret(pw)); | ||
|
||
const appKey = keyUnlocked.derive(index); | ||
|
||
const signedMessage = appKey.sign(message); | ||
|
||
keyUnlocked.zero(); | ||
appKey.zero(); | ||
|
||
const validatedSchema = SuccessMessageSignedSchema.safeParse({ | ||
signature: uint8ArrayToBase64(signedMessage) | ||
}); | ||
|
||
if (!validatedSchema.success) { | ||
throw new Error('Invalid message'); | ||
} | ||
|
||
return validatedSchema.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
holo-key-manager-extension/src/lib/queries/extensionQueries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './generate-keys'; | ||
export * from './manage-keys'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.