-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: ignore post install scripts on workflows * feat: add chakra-ui and load fonts * feat: add basic boilerplate for onboard app * feat: add logger utility function * build(yarn): add jest * test: add test for tohexstring utility function * feat: add utility function to convert hex string to bytes * feat: add private key stroage service * build(yarn): inject version and environment * feat: add a backagorund script that starts the onboarding window if it is not intialized * build(yarn): add react-i18next package * feat: add redux and move il8n initialization to window load * chore: squash * feat: add functionality to save credentials from redux * feat: add react router and add basic routing with animated transitions * feat: add password input and implement password strength feature * feat: add basic event dtos * chore: squash * refactor: rename password input * chore: squash * feat: add page to enter mnemonic * chore: squash * feat: fix issue with encrypting private key * build(yarn): add uuid package * feat: successfully save credentials to storage * test: configure jest for testing browser extension * chore: squash * chore: squash * fix: background script should successfully receive registration complete event * feat: add main and dashboard page * test: fix private key test using encyption polyfills * refactor: convert hex string to bytes before getting iv, salt and data * feat: add nivgate and toast to store and handle errors gracefully * build: update lint and prettier to run on tsx files * chore: squash * feat: add basic algorand window provider * ci: release on beta
- Loading branch information
1 parent
ab8a72f
commit d2b7549
Showing
157 changed files
with
13,719 additions
and
152 deletions.
There are no files selected for viewing
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,3 +1,4 @@ | ||
coverage/ | ||
build/ | ||
coverage/ | ||
dist/ | ||
node_modules/ |
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,3 +1,4 @@ | ||
module.exports = { | ||
'**/*.{js,json,ts}': (filenames) => `prettier --write ${filenames.join(' ')}`, | ||
'**/*.{js,json,ts,tsx}': (filenames) => | ||
`prettier --write ${filenames.join(' ')}`, | ||
}; |
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,3 +1,4 @@ | ||
dist/ | ||
coverage/ | ||
build/ | ||
dist/ | ||
node_modules/ |
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,21 @@ | ||
module.exports = { | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'<rootDir>/src/**/*.{ts,tsx}', | ||
'!<rootDir>/src/**/*.d.ts', | ||
], | ||
coverageDirectory: 'coverage', | ||
moduleFileExtensions: ['js', 'ts', 'tsx'], | ||
rootDir: '.', | ||
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'], | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
tsconfig: '<rootDir>/test/tsconfig.json', | ||
}, | ||
], | ||
}, | ||
verbose: true, | ||
}; |
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,4 @@ | ||
declare module '*.svg'; | ||
declare module '*.ttf'; | ||
declare module '*.woff'; | ||
declare module '*.woff2'; |
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,2 @@ | ||
declare const __ENV__: 'development' | 'production'; | ||
declare const __VERSION__: string; |
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,10 @@ | ||
import { Algorand } from './algorand-provider'; | ||
|
||
// Types | ||
import { IWindow } from './types'; | ||
|
||
(() => { | ||
if (!(window as IWindow).algorand) { | ||
(window as IWindow).algorand = new Algorand(); | ||
} | ||
})(); |
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,98 @@ | ||
// Entities | ||
import BaseProvider from './BaseProvider'; | ||
|
||
// Errors | ||
import { NoProvidersDetectedError } from '../errors'; | ||
|
||
// Types | ||
import { IAddProviderOptions } from '../types'; | ||
|
||
export default class Algorand { | ||
private defaultProviderIndex: number = 0; | ||
private providers: BaseProvider[]; | ||
|
||
constructor() { | ||
this.providers = []; | ||
} | ||
|
||
/** | ||
* Adds a provider, or if the `replace` option is set, will replace any existing providers matching by ID. | ||
* @param {BaseProvider} provider - the provider to add/replace. | ||
* @param {IAddProviderOptions} options - [optional] options that change the behavior when adding a provider. | ||
*/ | ||
public addProvider( | ||
provider: BaseProvider, | ||
options?: IAddProviderOptions | ||
): void { | ||
const existingProvider: BaseProvider | null = this.getProvider(provider.id); | ||
|
||
// if no provider exists, just add it | ||
if (!existingProvider) { | ||
this.providers.push(provider); | ||
} | ||
|
||
if (existingProvider && options?.replace) { | ||
this.providers = this.providers.map((value) => | ||
value.id === provider.id ? provider : value | ||
); | ||
} | ||
|
||
if (options?.makeDefault) { | ||
this.setDefaultProvider(provider.id); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the default provider. | ||
* @returns {BaseProvider | null} the default provider or null if no providers exist. | ||
*/ | ||
public getDefaultProvider(): BaseProvider | null { | ||
if (this.providers.length <= 0) { | ||
return null; | ||
} | ||
|
||
// if the default provider index is out of bounds, reset to 0. | ||
if (this.defaultProviderIndex > this.providers.length - 1) { | ||
this.defaultProviderIndex = 0; | ||
} | ||
|
||
return this.providers[this.defaultProviderIndex] || null; | ||
} | ||
|
||
/** | ||
* Gets the provider as specified by its ID. | ||
* @param {string} id - the ID of the provider. | ||
* @returns {BaseProvider | null} the provider if it exists, null otherwise. | ||
*/ | ||
public getProvider(id: string): BaseProvider | null { | ||
return this.providers.find((value) => value.id === id) || null; | ||
} | ||
|
||
/** | ||
* Gets all the providers. | ||
* @returns {BaseProvider[]} gets all teh providers. | ||
*/ | ||
public getProviders(): BaseProvider[] { | ||
return this.providers; | ||
} | ||
|
||
/** | ||
* Sets the default provider by ID. If the provider does not exist, the default provider is not changed. | ||
* @param {string} id - the ID of the provider to set to default. | ||
*/ | ||
public setDefaultProvider(id: string): void { | ||
const index: number = this.providers.findIndex((value) => value.id === id); | ||
|
||
this.defaultProviderIndex = index < 0 ? this.defaultProviderIndex : index; | ||
} | ||
|
||
public async signData(data: Uint8Array): Promise<Uint8Array> { | ||
const provider: BaseProvider | null = this.getDefaultProvider(); | ||
|
||
if (!provider) { | ||
throw new NoProvidersDetectedError('no providers detected'); | ||
} | ||
|
||
return provider.signData(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Algodv2 } from 'algosdk'; | ||
|
||
// Types | ||
import { INewBaseProviderOptions } from '../types'; | ||
|
||
export default abstract class BaseProvider { | ||
protected client: Algodv2; | ||
public id: string; | ||
|
||
constructor({ client, id }: INewBaseProviderOptions) { | ||
this.client = client; | ||
this.id = id; | ||
} | ||
|
||
public abstract signData(data: Uint8Array): Promise<Uint8Array>; | ||
} |
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,2 @@ | ||
export { default as Algorand } from './Algorand'; | ||
export { default as BaseProvider } from './BaseProvider'; |
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,9 @@ | ||
enum ErrorCodeEnum { | ||
// general errors | ||
UnknownError = 1000, | ||
|
||
// provider errors | ||
NoProvidersDetectedError = 2000, | ||
} | ||
|
||
export default ErrorCodeEnum; |
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 @@ | ||
export { default as ErrorCodeEnum } from './ErrorCodeEnum'; |
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,12 @@ | ||
// Enums | ||
import { ErrorCodeEnum } from '../enums'; | ||
|
||
export default abstract class BaseError extends Error { | ||
public readonly code: ErrorCodeEnum; | ||
public message: string; | ||
public readonly name: string; | ||
|
||
public constructor(message: string) { | ||
super(message.toLowerCase()); | ||
} | ||
} |
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,10 @@ | ||
// Enums | ||
import { ErrorCodeEnum } from '../enums'; | ||
|
||
// Errors | ||
import BaseError from './BaseError'; | ||
|
||
export default class NoProvidersDetectedError extends BaseError { | ||
public readonly code: ErrorCodeEnum = ErrorCodeEnum.NoProvidersDetectedError; | ||
public readonly name: string = 'NoProvidersDetectedError'; | ||
} |
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,10 @@ | ||
// Enums | ||
import { ErrorCodeEnum } from '../enums'; | ||
|
||
// Errors | ||
import BaseError from './BaseError'; | ||
|
||
export default class UnknownError extends BaseError { | ||
public readonly code: ErrorCodeEnum = ErrorCodeEnum.UnknownError; | ||
public readonly name: string = 'UnknownError'; | ||
} |
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,3 @@ | ||
export { default as BaseError } from './BaseError'; | ||
export { default as NoProvidersDetectedError } from './NoProvidersDetectedError'; | ||
export { default as UnknownError } from './UnknownError'; |
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,2 @@ | ||
export * from './entities'; | ||
export * from './types'; |
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,11 @@ | ||
/** | ||
* @property {boolean} makeDefault - [optional] sets the added/replaced provider as the default provider. Defaults to false. | ||
* @property {boolean} replace - [optional] determines whether a matching provider, by ID, should be replaced | ||
* with this one. Defaults to false. | ||
*/ | ||
interface IAddProviderOptions { | ||
makeDefault?: boolean; | ||
replace?: boolean; | ||
} | ||
|
||
export default IAddProviderOptions; |
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,8 @@ | ||
import { Algodv2 } from 'algosdk'; | ||
|
||
interface INewBaseProviderOptions { | ||
client: Algodv2; | ||
id: string; | ||
} | ||
|
||
export default INewBaseProviderOptions; |
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,2 @@ | ||
export type { default as IAddProviderOptions } from './IAddProviderOptions'; | ||
export type { default as INewBaseProviderOptions } from './INewBaseProviderOptions'; |
Oops, something went wrong.